Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
ReactJS / Javascript How to remove the duplicate array of objects from multi dimentional array?
const array = [
  {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153, …},
  {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153, …}
];
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

To remove the duplicate objects by checking for all the keys:

You have _.uniq function of underscore

const sourceArray = [ {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153}, {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153} ]
const destArray = _.uniq(sourceArray, function(x){
    return x.name;
});
console.log(destArray);
<script src="https://cdn.jsdelivr.net/npm/underscore@1.13.3/underscore-umd-min.js"></script>

If you want in plain Javascript

var uniqueProperties = {};

var array = [ {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153}, {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153} ]


for(var object in array){
   uniqueProperties[array[object]['name']] = array[object]['id'];
}

var uniqiueArray = [];

for(var uniqueName in uniqueProperties){
   uniqiueArray.push(
     { id: uniqueProperties[uniqueName], name:uniqueName });
}

console.log(uniqiueArray)

about 4 years ago · Juan Pablo Isaza Report

0

This question has already been answered before in here

let array = [
  {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153},
  {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153},
  {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153},
  {id: 1029, name: 'College-Annual-Day.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153},
  {id: 1030, name: 'College-Annual-Day-2.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153},
  {id: 1031, name: 'College-Annual-Day-3.jpg', ext: 'jpg', mime: 'image/jpeg', size: 91153}
];
array = array.filter((value, index, self) =>
  index === self.findIndex((t) => t.id === value.id
 )
)

console.log(array)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!