Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Remove the second occurrence of array object with same name in JS ?

By M.K. Verma · 3 May 2022

Remove the second occurrence of array object with same name in JS ?

Try This Code 

let users = [{name:'arrow',age:50,id:444},
  {name:'bow',age:66,id:884},
  {name:'arrow',age:30,id:99},
  {name:'apple',age: 50,id: 990},
  {name:'bow',age: 50,id: 9669}]

for (let i = 0; i < users.length; i++) {
  for(let x = 0; i < users.length; i++) {
    if(users[i].name == users[x].name) {
      users.splice(users[x], 1)
    }
  }
}