Removing duplicates from array is only returning one object









up vote
1
down vote

favorite












I am trying to remove duplicate entry's from this json but it is only returning one object I am not understanding where I am going wrong.



The code is as follows.



// exemplary array of objects (id 'NewLive' occurs twice)
var arr = [
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid",
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid"
],
obj = , new_arr = ;

// in the end the last unique object will be considered
arr.forEach(function(v)
obj[v['id']] = v;
console.log(JSON.stringify(new_arr));
);
new_arr = Object.keys(obj).map(function(id) return obj[id]; );

console.log(JSON.stringify(new_arr));


I am attaching codepen also with this.



https://codepen.io/anon/pen/oQXJWK










share|improve this question























  • Are you just trying to return the same object without duplicates?
    – Jacques
    yesterday










  • @Jacques Yes I am
    – Arun VM
    yesterday










  • Possible duplicate of Get all unique values in a JavaScript array (remove duplicates)
    – Frank Fajardo
    yesterday










  • obj[v['id']] = v; should be obj[v['jobcodeid']] = v;. Since there is no id, you get undefined for all objects and hence you are basically replacing all values by next. Hence you get only 1
    – Rajesh
    yesterday











  • for (const job of arr) if (!obj[job.jobcodeid.S]) obj[job.jobcodeid.S] = true; new_arr.push(job);
    – Jacques
    yesterday














up vote
1
down vote

favorite












I am trying to remove duplicate entry's from this json but it is only returning one object I am not understanding where I am going wrong.



The code is as follows.



// exemplary array of objects (id 'NewLive' occurs twice)
var arr = [
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid",
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid"
],
obj = , new_arr = ;

// in the end the last unique object will be considered
arr.forEach(function(v)
obj[v['id']] = v;
console.log(JSON.stringify(new_arr));
);
new_arr = Object.keys(obj).map(function(id) return obj[id]; );

console.log(JSON.stringify(new_arr));


I am attaching codepen also with this.



https://codepen.io/anon/pen/oQXJWK










share|improve this question























  • Are you just trying to return the same object without duplicates?
    – Jacques
    yesterday










  • @Jacques Yes I am
    – Arun VM
    yesterday










  • Possible duplicate of Get all unique values in a JavaScript array (remove duplicates)
    – Frank Fajardo
    yesterday










  • obj[v['id']] = v; should be obj[v['jobcodeid']] = v;. Since there is no id, you get undefined for all objects and hence you are basically replacing all values by next. Hence you get only 1
    – Rajesh
    yesterday











  • for (const job of arr) if (!obj[job.jobcodeid.S]) obj[job.jobcodeid.S] = true; new_arr.push(job);
    – Jacques
    yesterday












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to remove duplicate entry's from this json but it is only returning one object I am not understanding where I am going wrong.



The code is as follows.



// exemplary array of objects (id 'NewLive' occurs twice)
var arr = [
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid",
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid"
],
obj = , new_arr = ;

// in the end the last unique object will be considered
arr.forEach(function(v)
obj[v['id']] = v;
console.log(JSON.stringify(new_arr));
);
new_arr = Object.keys(obj).map(function(id) return obj[id]; );

console.log(JSON.stringify(new_arr));


I am attaching codepen also with this.



https://codepen.io/anon/pen/oQXJWK










share|improve this question















I am trying to remove duplicate entry's from this json but it is only returning one object I am not understanding where I am going wrong.



The code is as follows.



// exemplary array of objects (id 'NewLive' occurs twice)
var arr = [
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid",
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid"
],
obj = , new_arr = ;

// in the end the last unique object will be considered
arr.forEach(function(v)
obj[v['id']] = v;
console.log(JSON.stringify(new_arr));
);
new_arr = Object.keys(obj).map(function(id) return obj[id]; );

console.log(JSON.stringify(new_arr));


I am attaching codepen also with this.



https://codepen.io/anon/pen/oQXJWK







javascript arrays node.js json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









lucascaro

2,82011324




2,82011324










asked yesterday









Arun VM

669




669











  • Are you just trying to return the same object without duplicates?
    – Jacques
    yesterday










  • @Jacques Yes I am
    – Arun VM
    yesterday










  • Possible duplicate of Get all unique values in a JavaScript array (remove duplicates)
    – Frank Fajardo
    yesterday










  • obj[v['id']] = v; should be obj[v['jobcodeid']] = v;. Since there is no id, you get undefined for all objects and hence you are basically replacing all values by next. Hence you get only 1
    – Rajesh
    yesterday











  • for (const job of arr) if (!obj[job.jobcodeid.S]) obj[job.jobcodeid.S] = true; new_arr.push(job);
    – Jacques
    yesterday
















  • Are you just trying to return the same object without duplicates?
    – Jacques
    yesterday










  • @Jacques Yes I am
    – Arun VM
    yesterday










  • Possible duplicate of Get all unique values in a JavaScript array (remove duplicates)
    – Frank Fajardo
    yesterday










  • obj[v['id']] = v; should be obj[v['jobcodeid']] = v;. Since there is no id, you get undefined for all objects and hence you are basically replacing all values by next. Hence you get only 1
    – Rajesh
    yesterday











  • for (const job of arr) if (!obj[job.jobcodeid.S]) obj[job.jobcodeid.S] = true; new_arr.push(job);
    – Jacques
    yesterday















Are you just trying to return the same object without duplicates?
– Jacques
yesterday




Are you just trying to return the same object without duplicates?
– Jacques
yesterday












@Jacques Yes I am
– Arun VM
yesterday




@Jacques Yes I am
– Arun VM
yesterday












Possible duplicate of Get all unique values in a JavaScript array (remove duplicates)
– Frank Fajardo
yesterday




Possible duplicate of Get all unique values in a JavaScript array (remove duplicates)
– Frank Fajardo
yesterday












obj[v['id']] = v; should be obj[v['jobcodeid']] = v;. Since there is no id, you get undefined for all objects and hence you are basically replacing all values by next. Hence you get only 1
– Rajesh
yesterday





obj[v['id']] = v; should be obj[v['jobcodeid']] = v;. Since there is no id, you get undefined for all objects and hence you are basically replacing all values by next. Hence you get only 1
– Rajesh
yesterday













for (const job of arr) if (!obj[job.jobcodeid.S]) obj[job.jobcodeid.S] = true; new_arr.push(job);
– Jacques
yesterday




for (const job of arr) if (!obj[job.jobcodeid.S]) obj[job.jobcodeid.S] = true; new_arr.push(job);
– Jacques
yesterday












5 Answers
5






active

oldest

votes

















up vote
1
down vote



accepted










Fist of all, you have to use obj[v['jobcodeid']] = v; instead of obj[v['id']] = v;.



but as v[jobcodeid] is an object, js will convert it to a string i.e. [object Object] and you will only one element in final array.






// exemplary array of objects (id 'NewLive' occurs twice)
var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

// in the end the last unique object will be considered
arr.forEach(function(v)
obj[v['jobcodeid']] = v;
);
new_arr = Object.keys(obj).map(function(id) return obj[id]; );

console.log(JSON.stringify(new_arr));





You should use v.jobcodeid.S as keys of object.






// exemplary array of objects (id 'NewLive' occurs twice)
var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

// in the end the last unique object will be considered
arr.forEach(function(v)
obj[v.jobcodeid.S] = v;
);
new_arr = Object.keys(obj).map(function(id) return obj[id]; );

console.log(JSON.stringify(new_arr));








share|improve this answer






















  • I missed that in my comment. +1
    – Rajesh
    yesterday










  • Have you tested the code? Can u update the same on codepen?
    – Arun VM
    yesterday










  • Yeah i have updated the same pen any way
    – Arun VM
    yesterday










  • @ArunVM added code snippets.
    – nrgwsth
    yesterday










  • I have accepted the answer Peace :), Thank you
    – Arun VM
    yesterday


















up vote
4
down vote













Note that you are reading v['id'] but there is no id property on the objects.



Option 1: To Map and back



To filter duplicates you can convert the elements to a Map of key -> value, and then convert back into an array. This works because keys are unique in a Map, and duplicates will be automatically eliminated. The main advantage of this method is that due to the simplicity of the code it will have fewer bugs.



Option 2: filter



Another option is to use a Set to record known ids and filter to remove items with known ids. The advantage of this method is that it might be easier to read since the intention is explicit. Also this is more performant than converting to Map and back.






const input = [
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid",
"jobcodeid":"S":"Etc_new",
"jobcodeid":"S":"NewLive",
"jobcodeid":"S":"NewLiveVid",
"jobcodeid":"S":"New_Live",
"jobcodeid":"S":"New_Live_Vid",
"jobcodeid":"S":"Newest",
"jobcodeid":"S":"NewestLive",
"jobcodeid":"S":"NewestLiveVid",
"jobcodeid":"S":"Very_New_Vid"
]

// Option 1: To Map and back
console.log(
Array.from(
new Map(
input.map(i => [i.jobcodeid.S, i])
).values()
)
)

// Option 2: filter and set
const knownKeys = new Set();
console.log(
input.filter(i =>
if (!knownKeys.has(i.jobcodeid.S))
knownKeys.add(i.jobcodeid.S);
return true;

)
);





For the record, I ran benchmarks on the accepted solution, mine and the performance improvements from Jacques' answer



accepted solution x 1,892,585 ops/sec ±3.48% (89 runs sampled)
Map and back x 495,116 ops/sec ±2.27% (90 runs sampled)
Set and filter x 1,600,833 ops/sec ±1.98% (90 runs sampled)
Jacques x 2,110,510 ops/sec ±0.98% (92 runs sampled)
Fastest is Jacques


As you can see, Jacques' solution is indeed twice as fast so if you are aiming to filter huge arrays or if performance is key, you should definitely choose that!






share|improve this answer





























    up vote
    1
    down vote













    Posting an answer to show another way to do it with greater efficiency.






    var arr = [
    "jobcodeid":"S":"Etc_new"
    ,
    "jobcodeid":"S":"NewLive"
    ,
    "jobcodeid":"S":"NewLiveVid",
    "jobcodeid":"S":"New_Live",
    "jobcodeid":"S":"New_Live_Vid",
    "jobcodeid":"S":"Newest",
    "jobcodeid":"S":"NewestLive",
    "jobcodeid":"S":"NewestLiveVid",
    "jobcodeid":"S":"Very_New_Vid",
    "jobcodeid":"S":"Etc_new",
    "jobcodeid":"S":"NewLive",
    "jobcodeid":"S":"NewLiveVid",
    "jobcodeid":"S":"New_Live",
    "jobcodeid":"S":"New_Live_Vid",
    "jobcodeid":"S":"Newest",
    "jobcodeid":"S":"NewestLive",
    "jobcodeid":"S":"NewestLiveVid",
    "jobcodeid":"S":"Very_New_Vid"
    ],
    obj = , new_arr = ;

    // in the end the last unique object will be considered
    for (const job of arr)
    if (!obj[job.jobcodeid.S])
    obj[job.jobcodeid.S] = true;
    new_arr.push(job);



    console.log(JSON.stringify(new_arr));





    This answer is always runs N iterations. When you loop through the keys after setting the unique values, it can run up to 2N iterations. (Changed from talking about Big O/Complexity to be more clear)






    share|improve this answer






















    • O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
      – lucascaro
      yesterday










    • You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
      – Jacques
      yesterday






    • 1




      Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
      – lucascaro
      yesterday

















    up vote
    1
    down vote













    All you need is to use Set!



    const arr = [
    jobcodeid: S: "Etc_new" ,
    jobcodeid: S: "NewLive" ,
    jobcodeid: S: "NewLiveVid" ,
    jobcodeid: S: "New_Live" ,
    jobcodeid: S: "New_Live_Vid" ,
    jobcodeid: S: "Newest" ,
    jobcodeid: S: "NewestLive" ,
    jobcodeid: S: "NewestLiveVid" ,
    jobcodeid: S: "Very_New_Vid" ,
    jobcodeid: S: "Etc_new" ,
    jobcodeid: S: "NewLive" ,
    jobcodeid: S: "NewLiveVid" ,
    jobcodeid: S: "New_Live" ,
    jobcodeid: S: "New_Live_Vid" ,
    jobcodeid: S: "Newest" ,
    jobcodeid: S: "NewestLive" ,
    jobcodeid: S: "NewestLiveVid" ,
    jobcodeid: S: "Very_New_Vid"
    ];

    const uniqueItems = [...new Set(arr.map(i => i.jobcodeid.S))]





    share|improve this answer



























      up vote
      0
      down vote













      Try this also.. another way to solve this problem



      var arr = [
      "jobcodeid":"S":"Etc_new"
      ,
      "jobcodeid":"S":"NewLive"
      ,
      "jobcodeid":"S":"NewLiveVid",
      "jobcodeid":"S":"New_Live",
      "jobcodeid":"S":"New_Live_Vid",
      "jobcodeid":"S":"Newest",
      "jobcodeid":"S":"NewestLive",
      "jobcodeid":"S":"NewestLiveVid",
      "jobcodeid":"S":"Very_New_Vid",
      "jobcodeid":"S":"Etc_new",
      "jobcodeid":"S":"NewLive",
      "jobcodeid":"S":"NewLiveVid",
      "jobcodeid":"S":"New_Live",
      "jobcodeid":"S":"New_Live_Vid",
      "jobcodeid":"S":"Newest",
      "jobcodeid":"S":"NewestLive",
      "jobcodeid":"S":"NewestLiveVid",
      "jobcodeid":"S":"Very_New_Vid"
      ],
      obj = , new_arr = ;


      arr.forEach(function(v)
      obj[v['id']] = v;

      for(var i=0;i< new_arr.length;i++)
      if(new_arr[i].jobcodeid.S == v.jobcodeid.S)
      return;


      new_arr.push(v);
      );

      console.log(new_arr);





      share|improve this answer








      New contributor




      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

















      • While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
        – Jacques
        yesterday










      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220284%2fremoving-duplicates-from-array-is-only-returning-one-object%23new-answer', 'question_page');

      );

      Post as a guest






























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      Fist of all, you have to use obj[v['jobcodeid']] = v; instead of obj[v['id']] = v;.



      but as v[jobcodeid] is an object, js will convert it to a string i.e. [object Object] and you will only one element in final array.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v['jobcodeid']] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      You should use v.jobcodeid.S as keys of object.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v.jobcodeid.S] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));








      share|improve this answer






















      • I missed that in my comment. +1
        – Rajesh
        yesterday










      • Have you tested the code? Can u update the same on codepen?
        – Arun VM
        yesterday










      • Yeah i have updated the same pen any way
        – Arun VM
        yesterday










      • @ArunVM added code snippets.
        – nrgwsth
        yesterday










      • I have accepted the answer Peace :), Thank you
        – Arun VM
        yesterday















      up vote
      1
      down vote



      accepted










      Fist of all, you have to use obj[v['jobcodeid']] = v; instead of obj[v['id']] = v;.



      but as v[jobcodeid] is an object, js will convert it to a string i.e. [object Object] and you will only one element in final array.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v['jobcodeid']] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      You should use v.jobcodeid.S as keys of object.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v.jobcodeid.S] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));








      share|improve this answer






















      • I missed that in my comment. +1
        – Rajesh
        yesterday










      • Have you tested the code? Can u update the same on codepen?
        – Arun VM
        yesterday










      • Yeah i have updated the same pen any way
        – Arun VM
        yesterday










      • @ArunVM added code snippets.
        – nrgwsth
        yesterday










      • I have accepted the answer Peace :), Thank you
        – Arun VM
        yesterday













      up vote
      1
      down vote



      accepted







      up vote
      1
      down vote



      accepted






      Fist of all, you have to use obj[v['jobcodeid']] = v; instead of obj[v['id']] = v;.



      but as v[jobcodeid] is an object, js will convert it to a string i.e. [object Object] and you will only one element in final array.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v['jobcodeid']] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      You should use v.jobcodeid.S as keys of object.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v.jobcodeid.S] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));








      share|improve this answer














      Fist of all, you have to use obj[v['jobcodeid']] = v; instead of obj[v['id']] = v;.



      but as v[jobcodeid] is an object, js will convert it to a string i.e. [object Object] and you will only one element in final array.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v['jobcodeid']] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      You should use v.jobcodeid.S as keys of object.






      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v.jobcodeid.S] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));








      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v['jobcodeid']] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v['jobcodeid']] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v.jobcodeid.S] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));





      // exemplary array of objects (id 'NewLive' occurs twice)
      var arr=["jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid","jobcodeid":"S":"Etc_new","jobcodeid":"S":"NewLive","jobcodeid":"S":"NewLiveVid","jobcodeid":"S":"New_Live","jobcodeid":"S":"New_Live_Vid","jobcodeid":"S":"Newest","jobcodeid":"S":"NewestLive","jobcodeid":"S":"NewestLiveVid","jobcodeid":"S":"Very_New_Vid"], obj = , new_arr = ;

      // in the end the last unique object will be considered
      arr.forEach(function(v)
      obj[v.jobcodeid.S] = v;
      );
      new_arr = Object.keys(obj).map(function(id) return obj[id]; );

      console.log(JSON.stringify(new_arr));






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited yesterday

























      answered yesterday









      nrgwsth

      3,6781822




      3,6781822











      • I missed that in my comment. +1
        – Rajesh
        yesterday










      • Have you tested the code? Can u update the same on codepen?
        – Arun VM
        yesterday










      • Yeah i have updated the same pen any way
        – Arun VM
        yesterday










      • @ArunVM added code snippets.
        – nrgwsth
        yesterday










      • I have accepted the answer Peace :), Thank you
        – Arun VM
        yesterday

















      • I missed that in my comment. +1
        – Rajesh
        yesterday










      • Have you tested the code? Can u update the same on codepen?
        – Arun VM
        yesterday










      • Yeah i have updated the same pen any way
        – Arun VM
        yesterday










      • @ArunVM added code snippets.
        – nrgwsth
        yesterday










      • I have accepted the answer Peace :), Thank you
        – Arun VM
        yesterday
















      I missed that in my comment. +1
      – Rajesh
      yesterday




      I missed that in my comment. +1
      – Rajesh
      yesterday












      Have you tested the code? Can u update the same on codepen?
      – Arun VM
      yesterday




      Have you tested the code? Can u update the same on codepen?
      – Arun VM
      yesterday












      Yeah i have updated the same pen any way
      – Arun VM
      yesterday




      Yeah i have updated the same pen any way
      – Arun VM
      yesterday












      @ArunVM added code snippets.
      – nrgwsth
      yesterday




      @ArunVM added code snippets.
      – nrgwsth
      yesterday












      I have accepted the answer Peace :), Thank you
      – Arun VM
      yesterday





      I have accepted the answer Peace :), Thank you
      – Arun VM
      yesterday













      up vote
      4
      down vote













      Note that you are reading v['id'] but there is no id property on the objects.



      Option 1: To Map and back



      To filter duplicates you can convert the elements to a Map of key -> value, and then convert back into an array. This works because keys are unique in a Map, and duplicates will be automatically eliminated. The main advantage of this method is that due to the simplicity of the code it will have fewer bugs.



      Option 2: filter



      Another option is to use a Set to record known ids and filter to remove items with known ids. The advantage of this method is that it might be easier to read since the intention is explicit. Also this is more performant than converting to Map and back.






      const input = [
      "jobcodeid":"S":"Etc_new",
      "jobcodeid":"S":"NewLive",
      "jobcodeid":"S":"NewLiveVid",
      "jobcodeid":"S":"New_Live",
      "jobcodeid":"S":"New_Live_Vid",
      "jobcodeid":"S":"Newest",
      "jobcodeid":"S":"NewestLive",
      "jobcodeid":"S":"NewestLiveVid",
      "jobcodeid":"S":"Very_New_Vid",
      "jobcodeid":"S":"Etc_new",
      "jobcodeid":"S":"NewLive",
      "jobcodeid":"S":"NewLiveVid",
      "jobcodeid":"S":"New_Live",
      "jobcodeid":"S":"New_Live_Vid",
      "jobcodeid":"S":"Newest",
      "jobcodeid":"S":"NewestLive",
      "jobcodeid":"S":"NewestLiveVid",
      "jobcodeid":"S":"Very_New_Vid"
      ]

      // Option 1: To Map and back
      console.log(
      Array.from(
      new Map(
      input.map(i => [i.jobcodeid.S, i])
      ).values()
      )
      )

      // Option 2: filter and set
      const knownKeys = new Set();
      console.log(
      input.filter(i =>
      if (!knownKeys.has(i.jobcodeid.S))
      knownKeys.add(i.jobcodeid.S);
      return true;

      )
      );





      For the record, I ran benchmarks on the accepted solution, mine and the performance improvements from Jacques' answer



      accepted solution x 1,892,585 ops/sec ±3.48% (89 runs sampled)
      Map and back x 495,116 ops/sec ±2.27% (90 runs sampled)
      Set and filter x 1,600,833 ops/sec ±1.98% (90 runs sampled)
      Jacques x 2,110,510 ops/sec ±0.98% (92 runs sampled)
      Fastest is Jacques


      As you can see, Jacques' solution is indeed twice as fast so if you are aiming to filter huge arrays or if performance is key, you should definitely choose that!






      share|improve this answer


























        up vote
        4
        down vote













        Note that you are reading v['id'] but there is no id property on the objects.



        Option 1: To Map and back



        To filter duplicates you can convert the elements to a Map of key -> value, and then convert back into an array. This works because keys are unique in a Map, and duplicates will be automatically eliminated. The main advantage of this method is that due to the simplicity of the code it will have fewer bugs.



        Option 2: filter



        Another option is to use a Set to record known ids and filter to remove items with known ids. The advantage of this method is that it might be easier to read since the intention is explicit. Also this is more performant than converting to Map and back.






        const input = [
        "jobcodeid":"S":"Etc_new",
        "jobcodeid":"S":"NewLive",
        "jobcodeid":"S":"NewLiveVid",
        "jobcodeid":"S":"New_Live",
        "jobcodeid":"S":"New_Live_Vid",
        "jobcodeid":"S":"Newest",
        "jobcodeid":"S":"NewestLive",
        "jobcodeid":"S":"NewestLiveVid",
        "jobcodeid":"S":"Very_New_Vid",
        "jobcodeid":"S":"Etc_new",
        "jobcodeid":"S":"NewLive",
        "jobcodeid":"S":"NewLiveVid",
        "jobcodeid":"S":"New_Live",
        "jobcodeid":"S":"New_Live_Vid",
        "jobcodeid":"S":"Newest",
        "jobcodeid":"S":"NewestLive",
        "jobcodeid":"S":"NewestLiveVid",
        "jobcodeid":"S":"Very_New_Vid"
        ]

        // Option 1: To Map and back
        console.log(
        Array.from(
        new Map(
        input.map(i => [i.jobcodeid.S, i])
        ).values()
        )
        )

        // Option 2: filter and set
        const knownKeys = new Set();
        console.log(
        input.filter(i =>
        if (!knownKeys.has(i.jobcodeid.S))
        knownKeys.add(i.jobcodeid.S);
        return true;

        )
        );





        For the record, I ran benchmarks on the accepted solution, mine and the performance improvements from Jacques' answer



        accepted solution x 1,892,585 ops/sec ±3.48% (89 runs sampled)
        Map and back x 495,116 ops/sec ±2.27% (90 runs sampled)
        Set and filter x 1,600,833 ops/sec ±1.98% (90 runs sampled)
        Jacques x 2,110,510 ops/sec ±0.98% (92 runs sampled)
        Fastest is Jacques


        As you can see, Jacques' solution is indeed twice as fast so if you are aiming to filter huge arrays or if performance is key, you should definitely choose that!






        share|improve this answer
























          up vote
          4
          down vote










          up vote
          4
          down vote









          Note that you are reading v['id'] but there is no id property on the objects.



          Option 1: To Map and back



          To filter duplicates you can convert the elements to a Map of key -> value, and then convert back into an array. This works because keys are unique in a Map, and duplicates will be automatically eliminated. The main advantage of this method is that due to the simplicity of the code it will have fewer bugs.



          Option 2: filter



          Another option is to use a Set to record known ids and filter to remove items with known ids. The advantage of this method is that it might be easier to read since the intention is explicit. Also this is more performant than converting to Map and back.






          const input = [
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid",
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid"
          ]

          // Option 1: To Map and back
          console.log(
          Array.from(
          new Map(
          input.map(i => [i.jobcodeid.S, i])
          ).values()
          )
          )

          // Option 2: filter and set
          const knownKeys = new Set();
          console.log(
          input.filter(i =>
          if (!knownKeys.has(i.jobcodeid.S))
          knownKeys.add(i.jobcodeid.S);
          return true;

          )
          );





          For the record, I ran benchmarks on the accepted solution, mine and the performance improvements from Jacques' answer



          accepted solution x 1,892,585 ops/sec ±3.48% (89 runs sampled)
          Map and back x 495,116 ops/sec ±2.27% (90 runs sampled)
          Set and filter x 1,600,833 ops/sec ±1.98% (90 runs sampled)
          Jacques x 2,110,510 ops/sec ±0.98% (92 runs sampled)
          Fastest is Jacques


          As you can see, Jacques' solution is indeed twice as fast so if you are aiming to filter huge arrays or if performance is key, you should definitely choose that!






          share|improve this answer














          Note that you are reading v['id'] but there is no id property on the objects.



          Option 1: To Map and back



          To filter duplicates you can convert the elements to a Map of key -> value, and then convert back into an array. This works because keys are unique in a Map, and duplicates will be automatically eliminated. The main advantage of this method is that due to the simplicity of the code it will have fewer bugs.



          Option 2: filter



          Another option is to use a Set to record known ids and filter to remove items with known ids. The advantage of this method is that it might be easier to read since the intention is explicit. Also this is more performant than converting to Map and back.






          const input = [
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid",
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid"
          ]

          // Option 1: To Map and back
          console.log(
          Array.from(
          new Map(
          input.map(i => [i.jobcodeid.S, i])
          ).values()
          )
          )

          // Option 2: filter and set
          const knownKeys = new Set();
          console.log(
          input.filter(i =>
          if (!knownKeys.has(i.jobcodeid.S))
          knownKeys.add(i.jobcodeid.S);
          return true;

          )
          );





          For the record, I ran benchmarks on the accepted solution, mine and the performance improvements from Jacques' answer



          accepted solution x 1,892,585 ops/sec ±3.48% (89 runs sampled)
          Map and back x 495,116 ops/sec ±2.27% (90 runs sampled)
          Set and filter x 1,600,833 ops/sec ±1.98% (90 runs sampled)
          Jacques x 2,110,510 ops/sec ±0.98% (92 runs sampled)
          Fastest is Jacques


          As you can see, Jacques' solution is indeed twice as fast so if you are aiming to filter huge arrays or if performance is key, you should definitely choose that!






          const input = [
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid",
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid"
          ]

          // Option 1: To Map and back
          console.log(
          Array.from(
          new Map(
          input.map(i => [i.jobcodeid.S, i])
          ).values()
          )
          )

          // Option 2: filter and set
          const knownKeys = new Set();
          console.log(
          input.filter(i =>
          if (!knownKeys.has(i.jobcodeid.S))
          knownKeys.add(i.jobcodeid.S);
          return true;

          )
          );





          const input = [
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid",
          "jobcodeid":"S":"Etc_new",
          "jobcodeid":"S":"NewLive",
          "jobcodeid":"S":"NewLiveVid",
          "jobcodeid":"S":"New_Live",
          "jobcodeid":"S":"New_Live_Vid",
          "jobcodeid":"S":"Newest",
          "jobcodeid":"S":"NewestLive",
          "jobcodeid":"S":"NewestLiveVid",
          "jobcodeid":"S":"Very_New_Vid"
          ]

          // Option 1: To Map and back
          console.log(
          Array.from(
          new Map(
          input.map(i => [i.jobcodeid.S, i])
          ).values()
          )
          )

          // Option 2: filter and set
          const knownKeys = new Set();
          console.log(
          input.filter(i =>
          if (!knownKeys.has(i.jobcodeid.S))
          knownKeys.add(i.jobcodeid.S);
          return true;

          )
          );






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          lucascaro

          2,82011324




          2,82011324




















              up vote
              1
              down vote













              Posting an answer to show another way to do it with greater efficiency.






              var arr = [
              "jobcodeid":"S":"Etc_new"
              ,
              "jobcodeid":"S":"NewLive"
              ,
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid",
              "jobcodeid":"S":"Etc_new",
              "jobcodeid":"S":"NewLive",
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid"
              ],
              obj = , new_arr = ;

              // in the end the last unique object will be considered
              for (const job of arr)
              if (!obj[job.jobcodeid.S])
              obj[job.jobcodeid.S] = true;
              new_arr.push(job);



              console.log(JSON.stringify(new_arr));





              This answer is always runs N iterations. When you loop through the keys after setting the unique values, it can run up to 2N iterations. (Changed from talking about Big O/Complexity to be more clear)






              share|improve this answer






















              • O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
                – lucascaro
                yesterday










              • You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
                – Jacques
                yesterday






              • 1




                Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
                – lucascaro
                yesterday














              up vote
              1
              down vote













              Posting an answer to show another way to do it with greater efficiency.






              var arr = [
              "jobcodeid":"S":"Etc_new"
              ,
              "jobcodeid":"S":"NewLive"
              ,
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid",
              "jobcodeid":"S":"Etc_new",
              "jobcodeid":"S":"NewLive",
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid"
              ],
              obj = , new_arr = ;

              // in the end the last unique object will be considered
              for (const job of arr)
              if (!obj[job.jobcodeid.S])
              obj[job.jobcodeid.S] = true;
              new_arr.push(job);



              console.log(JSON.stringify(new_arr));





              This answer is always runs N iterations. When you loop through the keys after setting the unique values, it can run up to 2N iterations. (Changed from talking about Big O/Complexity to be more clear)






              share|improve this answer






















              • O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
                – lucascaro
                yesterday










              • You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
                – Jacques
                yesterday






              • 1




                Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
                – lucascaro
                yesterday












              up vote
              1
              down vote










              up vote
              1
              down vote









              Posting an answer to show another way to do it with greater efficiency.






              var arr = [
              "jobcodeid":"S":"Etc_new"
              ,
              "jobcodeid":"S":"NewLive"
              ,
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid",
              "jobcodeid":"S":"Etc_new",
              "jobcodeid":"S":"NewLive",
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid"
              ],
              obj = , new_arr = ;

              // in the end the last unique object will be considered
              for (const job of arr)
              if (!obj[job.jobcodeid.S])
              obj[job.jobcodeid.S] = true;
              new_arr.push(job);



              console.log(JSON.stringify(new_arr));





              This answer is always runs N iterations. When you loop through the keys after setting the unique values, it can run up to 2N iterations. (Changed from talking about Big O/Complexity to be more clear)






              share|improve this answer














              Posting an answer to show another way to do it with greater efficiency.






              var arr = [
              "jobcodeid":"S":"Etc_new"
              ,
              "jobcodeid":"S":"NewLive"
              ,
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid",
              "jobcodeid":"S":"Etc_new",
              "jobcodeid":"S":"NewLive",
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid"
              ],
              obj = , new_arr = ;

              // in the end the last unique object will be considered
              for (const job of arr)
              if (!obj[job.jobcodeid.S])
              obj[job.jobcodeid.S] = true;
              new_arr.push(job);



              console.log(JSON.stringify(new_arr));





              This answer is always runs N iterations. When you loop through the keys after setting the unique values, it can run up to 2N iterations. (Changed from talking about Big O/Complexity to be more clear)






              var arr = [
              "jobcodeid":"S":"Etc_new"
              ,
              "jobcodeid":"S":"NewLive"
              ,
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid",
              "jobcodeid":"S":"Etc_new",
              "jobcodeid":"S":"NewLive",
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid"
              ],
              obj = , new_arr = ;

              // in the end the last unique object will be considered
              for (const job of arr)
              if (!obj[job.jobcodeid.S])
              obj[job.jobcodeid.S] = true;
              new_arr.push(job);



              console.log(JSON.stringify(new_arr));





              var arr = [
              "jobcodeid":"S":"Etc_new"
              ,
              "jobcodeid":"S":"NewLive"
              ,
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid",
              "jobcodeid":"S":"Etc_new",
              "jobcodeid":"S":"NewLive",
              "jobcodeid":"S":"NewLiveVid",
              "jobcodeid":"S":"New_Live",
              "jobcodeid":"S":"New_Live_Vid",
              "jobcodeid":"S":"Newest",
              "jobcodeid":"S":"NewestLive",
              "jobcodeid":"S":"NewestLiveVid",
              "jobcodeid":"S":"Very_New_Vid"
              ],
              obj = , new_arr = ;

              // in the end the last unique object will be considered
              for (const job of arr)
              if (!obj[job.jobcodeid.S])
              obj[job.jobcodeid.S] = true;
              new_arr.push(job);



              console.log(JSON.stringify(new_arr));






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited yesterday

























              answered yesterday









              Jacques

              2,25721135




              2,25721135











              • O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
                – lucascaro
                yesterday










              • You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
                – Jacques
                yesterday






              • 1




                Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
                – lucascaro
                yesterday
















              • O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
                – lucascaro
                yesterday










              • You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
                – Jacques
                yesterday






              • 1




                Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
                – lucascaro
                yesterday















              O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
              – lucascaro
              yesterday




              O(2n) is exactly the same as O(n) -- en.wikipedia.org/wiki/Big_O_notation
              – lucascaro
              yesterday












              You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
              – Jacques
              yesterday




              You are correct, I shouldn't use big o to explain this as it is technically used to explain how complexity grows as quantity increases. My point is that the one solution can take twice as long to complete as the other.
              – Jacques
              yesterday




              1




              1




              Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
              – lucascaro
              yesterday




              Even though looping twice doesn't necessarily mean slower, you are running fewer operations total, so you are right, this code would perform faster. I ran some quick benchmarks that confirm that this solution works roughly 2x faster than the next best :)
              – lucascaro
              yesterday










              up vote
              1
              down vote













              All you need is to use Set!



              const arr = [
              jobcodeid: S: "Etc_new" ,
              jobcodeid: S: "NewLive" ,
              jobcodeid: S: "NewLiveVid" ,
              jobcodeid: S: "New_Live" ,
              jobcodeid: S: "New_Live_Vid" ,
              jobcodeid: S: "Newest" ,
              jobcodeid: S: "NewestLive" ,
              jobcodeid: S: "NewestLiveVid" ,
              jobcodeid: S: "Very_New_Vid" ,
              jobcodeid: S: "Etc_new" ,
              jobcodeid: S: "NewLive" ,
              jobcodeid: S: "NewLiveVid" ,
              jobcodeid: S: "New_Live" ,
              jobcodeid: S: "New_Live_Vid" ,
              jobcodeid: S: "Newest" ,
              jobcodeid: S: "NewestLive" ,
              jobcodeid: S: "NewestLiveVid" ,
              jobcodeid: S: "Very_New_Vid"
              ];

              const uniqueItems = [...new Set(arr.map(i => i.jobcodeid.S))]





              share|improve this answer
























                up vote
                1
                down vote













                All you need is to use Set!



                const arr = [
                jobcodeid: S: "Etc_new" ,
                jobcodeid: S: "NewLive" ,
                jobcodeid: S: "NewLiveVid" ,
                jobcodeid: S: "New_Live" ,
                jobcodeid: S: "New_Live_Vid" ,
                jobcodeid: S: "Newest" ,
                jobcodeid: S: "NewestLive" ,
                jobcodeid: S: "NewestLiveVid" ,
                jobcodeid: S: "Very_New_Vid" ,
                jobcodeid: S: "Etc_new" ,
                jobcodeid: S: "NewLive" ,
                jobcodeid: S: "NewLiveVid" ,
                jobcodeid: S: "New_Live" ,
                jobcodeid: S: "New_Live_Vid" ,
                jobcodeid: S: "Newest" ,
                jobcodeid: S: "NewestLive" ,
                jobcodeid: S: "NewestLiveVid" ,
                jobcodeid: S: "Very_New_Vid"
                ];

                const uniqueItems = [...new Set(arr.map(i => i.jobcodeid.S))]





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  All you need is to use Set!



                  const arr = [
                  jobcodeid: S: "Etc_new" ,
                  jobcodeid: S: "NewLive" ,
                  jobcodeid: S: "NewLiveVid" ,
                  jobcodeid: S: "New_Live" ,
                  jobcodeid: S: "New_Live_Vid" ,
                  jobcodeid: S: "Newest" ,
                  jobcodeid: S: "NewestLive" ,
                  jobcodeid: S: "NewestLiveVid" ,
                  jobcodeid: S: "Very_New_Vid" ,
                  jobcodeid: S: "Etc_new" ,
                  jobcodeid: S: "NewLive" ,
                  jobcodeid: S: "NewLiveVid" ,
                  jobcodeid: S: "New_Live" ,
                  jobcodeid: S: "New_Live_Vid" ,
                  jobcodeid: S: "Newest" ,
                  jobcodeid: S: "NewestLive" ,
                  jobcodeid: S: "NewestLiveVid" ,
                  jobcodeid: S: "Very_New_Vid"
                  ];

                  const uniqueItems = [...new Set(arr.map(i => i.jobcodeid.S))]





                  share|improve this answer












                  All you need is to use Set!



                  const arr = [
                  jobcodeid: S: "Etc_new" ,
                  jobcodeid: S: "NewLive" ,
                  jobcodeid: S: "NewLiveVid" ,
                  jobcodeid: S: "New_Live" ,
                  jobcodeid: S: "New_Live_Vid" ,
                  jobcodeid: S: "Newest" ,
                  jobcodeid: S: "NewestLive" ,
                  jobcodeid: S: "NewestLiveVid" ,
                  jobcodeid: S: "Very_New_Vid" ,
                  jobcodeid: S: "Etc_new" ,
                  jobcodeid: S: "NewLive" ,
                  jobcodeid: S: "NewLiveVid" ,
                  jobcodeid: S: "New_Live" ,
                  jobcodeid: S: "New_Live_Vid" ,
                  jobcodeid: S: "Newest" ,
                  jobcodeid: S: "NewestLive" ,
                  jobcodeid: S: "NewestLiveVid" ,
                  jobcodeid: S: "Very_New_Vid"
                  ];

                  const uniqueItems = [...new Set(arr.map(i => i.jobcodeid.S))]






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Phap Duong Dieu

                  592




                  592




















                      up vote
                      0
                      down vote













                      Try this also.. another way to solve this problem



                      var arr = [
                      "jobcodeid":"S":"Etc_new"
                      ,
                      "jobcodeid":"S":"NewLive"
                      ,
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid",
                      "jobcodeid":"S":"Etc_new",
                      "jobcodeid":"S":"NewLive",
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid"
                      ],
                      obj = , new_arr = ;


                      arr.forEach(function(v)
                      obj[v['id']] = v;

                      for(var i=0;i< new_arr.length;i++)
                      if(new_arr[i].jobcodeid.S == v.jobcodeid.S)
                      return;


                      new_arr.push(v);
                      );

                      console.log(new_arr);





                      share|improve this answer








                      New contributor




                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

















                      • While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
                        – Jacques
                        yesterday














                      up vote
                      0
                      down vote













                      Try this also.. another way to solve this problem



                      var arr = [
                      "jobcodeid":"S":"Etc_new"
                      ,
                      "jobcodeid":"S":"NewLive"
                      ,
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid",
                      "jobcodeid":"S":"Etc_new",
                      "jobcodeid":"S":"NewLive",
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid"
                      ],
                      obj = , new_arr = ;


                      arr.forEach(function(v)
                      obj[v['id']] = v;

                      for(var i=0;i< new_arr.length;i++)
                      if(new_arr[i].jobcodeid.S == v.jobcodeid.S)
                      return;


                      new_arr.push(v);
                      );

                      console.log(new_arr);





                      share|improve this answer








                      New contributor




                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

















                      • While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
                        – Jacques
                        yesterday












                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      Try this also.. another way to solve this problem



                      var arr = [
                      "jobcodeid":"S":"Etc_new"
                      ,
                      "jobcodeid":"S":"NewLive"
                      ,
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid",
                      "jobcodeid":"S":"Etc_new",
                      "jobcodeid":"S":"NewLive",
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid"
                      ],
                      obj = , new_arr = ;


                      arr.forEach(function(v)
                      obj[v['id']] = v;

                      for(var i=0;i< new_arr.length;i++)
                      if(new_arr[i].jobcodeid.S == v.jobcodeid.S)
                      return;


                      new_arr.push(v);
                      );

                      console.log(new_arr);





                      share|improve this answer








                      New contributor




                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      Try this also.. another way to solve this problem



                      var arr = [
                      "jobcodeid":"S":"Etc_new"
                      ,
                      "jobcodeid":"S":"NewLive"
                      ,
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid",
                      "jobcodeid":"S":"Etc_new",
                      "jobcodeid":"S":"NewLive",
                      "jobcodeid":"S":"NewLiveVid",
                      "jobcodeid":"S":"New_Live",
                      "jobcodeid":"S":"New_Live_Vid",
                      "jobcodeid":"S":"Newest",
                      "jobcodeid":"S":"NewestLive",
                      "jobcodeid":"S":"NewestLiveVid",
                      "jobcodeid":"S":"Very_New_Vid"
                      ],
                      obj = , new_arr = ;


                      arr.forEach(function(v)
                      obj[v['id']] = v;

                      for(var i=0;i< new_arr.length;i++)
                      if(new_arr[i].jobcodeid.S == v.jobcodeid.S)
                      return;


                      new_arr.push(v);
                      );

                      console.log(new_arr);






                      share|improve this answer








                      New contributor




                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      share|improve this answer



                      share|improve this answer






                      New contributor




                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      answered yesterday









                      GaneshMani

                      11




                      11




                      New contributor




                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.





                      New contributor





                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






                      GaneshMani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.











                      • While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
                        – Jacques
                        yesterday
















                      • While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
                        – Jacques
                        yesterday















                      While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
                      – Jacques
                      yesterday




                      While this would work, please consider code complexity here. You have a loop within a loop, which is very inefficient.
                      – Jacques
                      yesterday

















                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220284%2fremoving-duplicates-from-array-is-only-returning-one-object%23new-answer', 'question_page');

                      );

                      Post as a guest














































































                      這個網誌中的熱門文章

                      Is there any way to eliminate the singular point to solve this integral by hand or by approximations?

                      Why am i infinitely getting the same tweet with the Twitter Search API?

                      Solve: $(3xy-2ay^2)dx+(x^2-2axy)dy=0$