我有一个包含重复条目的String列表,所以无论大小写如何,我都想删除它们
let duplicates = ['Hello', 'Hi', 'hello'];
let uniques = _.methodName(duplicates);
// output should be
['hello','Hi'] OR ['Hello','Hi']
您可以使用_.uniqWith()
以下回调:
let duplicates = ['Hello', 'Hi', 'hello'];
let uniques = _.uniqWith(duplicates, (a,b) => a.toLowerCase() === b.toLowerCase())
console.log(uniques);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句