Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to find unique values from an array in sorted order js

const arr = [1, 1, 1, 3, 2, 2, 8, 3, 4];
const uniqSort = (arr = []) => {
   const map = {};
   const res = [];
   for (let i = 0; i < arr.length; i++) {
      if (!map[arr[i]]) {
         map[arr[i]] = true;
         res.push(arr[i]);
      };
   };
   return res.sort((a, b) => a − b);
};
console.log(uniqSort(arr));
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #How #find #unique #values #array #sorted #order #js
ADD COMMENT
Topic
Name
5+7 =