gpt4 book ai didi

javascript - lodash.uniq 不工作

转载 作者:行者123 更新时间:2023-11-30 15:06:32 25 4
gpt4 key购买 nike

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.6/lodash.min.js"></script>

<script>
var topicData = []; //some data here

var topicList = topicData.map((d) => {
return d.topic;
})
_.uniq(topicList); //not work, still the old array

</script>

请问是我导入库错误还是其他原因。感谢您的帮助。

最佳答案

uniq返回一个新数组而不是改变现有数组。

来自文档:

Creates a duplicate-free version of an array, using SameValueZero for equality comparisons, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.

所以你应该做类似下面的事情。

const uniqueTopicList = _.uniq(topicList)

关于javascript - lodash.uniq 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45662804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com