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

255
Views
How to find unique value from an array in sorted order using for loop and sort() in javascript?

My array is:

const arr = [1, 4, 8, 10, 5, 7, 5, 9, 7, 5, 44, 6]

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

0

This is how you could go about sorting your array:

const arr = [1, 5, 7, 44, 5, 9, 4, 5, 9, 10, 6, 7, 8];

const uniqueArr = arr.filter(function(item, idx, self) {
    return self.indexOf(item) == idx;
})

const sortedArr = uniqueArr.sort(function(a, b) {
    return a - b;
});
console.log(sortedArr);
about 4 years ago · Juan Pablo Isaza Report

0

const arr = [1, 4, 8, 10, 5, 7, 5, 9, 7, 5, 44, 6];
      arr.sort((a,b) => {return a - b;});
let len = arr.length;
const unique = [];

for(let i = 0; i < len; i++){
  if(unique.indexOf(arr[i]) === -1){
     unique.push(arr[i]);
  }
}

console.log(unique);
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!