这是一个数组:[2,2,3,3,5,7,9,9]
从这个数组中,我需要这些值,但它没有重复项。如何获得?
const onlyUniqueWithoutDup = array.filter((item) => !item.indexOf(array))
查找结果为:[5,7]
;
有什么帮助吗?
最佳答案
您可以使用:
const array = [2,2,3,3,5,7,9,9];
const result = array.filter((item, index, arr) => (arr.lastIndexOf(item) == arr.indexOf(item)));
console.log(result);
关于javascript - 如何从数组中仅获取不重复的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59713396/