Sunday, October 23, 2022

Get unique values from array and remove duplicates

Extract unique values from arr1:

let arr1 = [1, 0, 1, 1, 2, 0, 2, 0, 2, 2];
    console.log( arr1.filter((el, i, a) => a.indexOf(el) === i) );
(3) [1, 0, 2]

 https://stackoverflow.com/questions/66527958/only-add-item-to-array-if-unique-otherwise-delete-react

https://stackoverflow.com/questions/11246758/how-to-get-unique-values-in-an-array

https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates

https://stackoverflow.com/questions/15125920/how-to-get-distinct-values-from-an-array-of-objects-in-javascript

No comments:

Post a Comment