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

305
Views
Check in an array ids are equals to dispatch the id value

I create an array of ids value mapping an existing array

const ids = array.map(item => ({ id: item.homologationId }));

This is the result

ids =[{ "id": "15079"},{"id": "15079"},{"id": "15079"},{"id": "15079"},]

From here i want to check if for each item of the ids array the id values are the same ( like in this example ) i want to dispatch in the store the id value (dispatch(setIdValue(value));

How can i do this check?

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

0

You're looking for the .every() Javascript Array method.

Something like this will do the trick.

const ids = array.map(item => ({ id: item.homologationId }));
const [head] = ids
if (head && ids.every(item => item.id == head.id)) {
    dispatch(setIdValue(head.id))
}
about 4 years ago · Juan Pablo Isaza Report

0

I would use every function to check the equality of the ids, this function returns true if the all the elements in an iterable fulfills a condition.

const ids =[{ "id": "15079"},{"id": "15079"},{"id": "15079"},{"id": "15079"}]

const element = ids.at(0);
if(ids.every(x => x.id === element.id)) {
  console.log("All the elements are equals")
} else {
  console.log("Not all the elements are equals")
}

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!