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

165
Views
How to check fields in array of objects are same in javascript

I have an array of objects how to check all fields except two fields are same using javascript

except cid and id , check all fields are same, if so return true else false

// 
var arrobj1=[
  {id:1, cid:"20", name:"rsx", value: "200"},
  {id:2, cid:"18", name:"rsx", value: "200", }
]
Expected Output:
true

var arrobj2=[
  {id:1, cid:"20", name:"ssa", value: "200"},
  {id:2, cid:"18", name:"rsx", value: "200", }
]
Expected Output:
false
var result =  [...new Map(arrobj1.map(v => [v.name, v.value])).values()];
if(result.length >0){
return true;
}else{return false;}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use array.every() method:

const arrobj1 = [{
    id: 1,
    cid: "20",
    name: "rsx",
    value: "200"
  },
  {
    id: 2,
    cid: "18",
    name: "rsx",
    value: "200"
  }
]

const arrobj2 = [{
    id: 1,
    cid: "20",
    name: "ssa",
    value: "200"
  },
  {
    id: 2,
    cid: "18",
    name: "rsx",
    value: "200"
  }
]

const areSameObjectsArray = (objArr) => {
  const firstObj = objArr[0];
  const ignoredProperties = new Set(['id', 'cid']);

  return objArr.every(checkObj => {
    for (const key in checkObj) {
      if (ignoredProperties.has(key)) continue;

      if (firstObj[key] !== checkObj[key]) return false;
    }

    return true;
  })
};

console.log(areSameObjectsArray(arrobj1));
console.log(areSameObjectsArray(arrobj2));

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!