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

272
Views
Removing duplicates of an array
How can i check if an array has element twice and log only the element that is not.
const duplicateElements = (array) => {

for(let numbers of array) {

 // code here

}
 
}

const numbers = [1,3,2,4,1,3,2];

duplicateElements(numbers);

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

0

With the JS function filter you can archive this. First you have to iterate your array. then check with the filter function how many times the current value is inside your array. If equal 1 then push to an result array.

const d = [];
const arr = [1,3,2,4,1,3,2]
arr.forEach((e) => { 
  if (arr.filter(x => x == e).length === 1) {    
    d.push(e);    
  }   
}) 

console.log(d);

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!