A solution that conforms to the meaning of the question
function unique(arr) {
const res = new Map();
return arr.filter((a) => !res.has(a) && res.set(a, 1))
}
because map key is unique, you can change the an in res.has (a) to whatever attribute you want to deduplicate, such as a.name
.reference:
Arrow function
return arr.filter((a) => !res.has(a) && res.set(a, 1))
//
return arr.filter(function(a){
return !res.has(a) && res.set(a, 1);
});
1, the arrow function has a more concise syntax for writing code;
2, this will not be bound.
Segmentation line, the following is my personal question, which is somewhat different from the question, and adopts the answer that meets my personal question. I"m sorry
that"s what I wrote.
referred to
https://codeshelper.com/q/10.
https://blog.csdn.net/zhihua_.
questions and articles, but I don"t feel very elegant. I don"t seem to use anything new in es6. Is there a better way to implement es6? Thank you
getGameVersionList() {
const versionList = this.page.resultList
const versionSet = [0]
const hash = {}
for (var i = 0, gameVersion; (gameVersion = versionList[i]) != null; iPP) {
if (!hash[gameVersion.gameVersionNo]) {
versionSet.push(gameVersion.gameVersionNo)
hash[gameVersion.gameVersionNo] = true
}
}
this.gameVersionNoSet = versionSet
},