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

140
Views
check array of objects if specific value is unique across all the array

I have an array like this

const arr = [{ name: 'sara' }, { name: 'joe' }];

and i want to check if name is unique across the array so

const arr = [{ name: 'sara' }, { name: 'joe' }];//sara is unique //true
const arr = [{ name: 'sara' }, { name: 'sara' },{ name: 'joe' }];//sara is unique //false

i know there's array.some but it doesn't help in my situation

whats is the best way to achieve that using javascript thanks in advance

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

0

You could take a single loop and a Set for seen value.

isUnique is a function which takes a property name and returns a function for Array#every.

const
    isUnique = (key, s = new Set) => o => !s.has(o[key]) && s.add(o[key]),
    a = [{ name: 'sara' }, { name: 'joe' }],
    b = [{ name: 'sara' }, { name: 'sara' }, { name: 'joe' }];

console.log(a.every(isUnique('name'))); //  true
console.log(b.every(isUnique('name'))); // false

about 4 years ago · Juan Pablo Isaza Report

0

i have this implementation and it dose the job

const arr = [{ name: "salah" }, { name: "joe" }];

let bols = [];
arr.forEach((item1, i1) => {
  arr.forEach((item2, i2) => {
    if (i1 !== i2) {
      bols.push(item2.name === item1.name);
    }
  });
});

bols.some((item) => item === true);
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!