When you look at any programming language, you see missing features that you find puzzling because the use case seems so common. One such case is retrieving unique values from an array with JavaScript. Years ago I mentioned an using objects instead of arrays, but that's not always an option and doesn't match every use case.
当您使用任何一种编程语言时,都会发现缺少的功能,这些功能令人困惑,因为用例似乎很常见。 一种这样的情况是使用JavaScript从数组中检索唯一值。 几年前,我提到了使用对象而不是数组的 ,但这并不总是一种选择,并且并不适合每个用例。
Want to retrieve a unique array of values from an array that may include duplicate values? You can use new JavaScript spread operator with Set to get an array of unique values:
是否想从可能包含重复值的数组中检索值的唯一数组? 您可以将新JavaScript Spread运算符与Set一起使用,以获取唯一值数组:
var j = [...new Set([1, 2, 3, 3])]>> [1, 2, 3]
Getting unique array values is another . And don't forget you can
获得唯一的数组值是另一种 。 并且不要忘记,您可以
There's no better feeling than being able to remove a library to complete a task that should be native to the language. This trick brings us one step closer to that!
没有什么比删除库来完成该语言固有的任务更好的感觉了。 这个技巧使我们更接近了这一步!
翻译自: