We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var users=[{ id:1,name:"a" },{ id:2,name:"a" },{ id:3,name:"b" },{ id:4,name:"v" }] Array.prototype.unique = function () { var res; this.map(item => { this[item.id - 1] = item.name }) // ES6里新添加了两个很好用的东西,set和Array.from // set是一种新的数据结构,它可以接收一个数组或者是类数组对象,自动去重其中的重复项目。 res=new Set(this); console.log("new Set对象",res) // 但是这里大家可以看到,set返回的是一个对象,但是我们想要的是数组啊。 // 这回,就该轮到Array.from出场了,它的作用,就是可以把类数组对象、可迭代对象转化为数组。 res=Array.from(new Set(this)); return res//es6 数组去重 } console.log(users.unique());
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: