javascript Knowledge Network access point

1, the filter value unique

ES6 the set object type, with the unfolding operation ... together, you can use it to create a new array, the array so that only unique values.

eg.

const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]

 This method is applicable to an array comprising basic undefinedtypes: null, boolean, , stringand number. (If you have an object, function, or other array contains an array, you need a different approach!)

 

Subsequent updates

 

Guess you like

Origin www.cnblogs.com/tiramisu-lizi/p/10928872.html
Recommended