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
利用对象属性名的唯一性对数组去重
let uniqueArr = (arr) => { let obj = {} let newArr = [] arr.forEach(item => { if (!obj.hasOwnProperty(item)) { obj[item] = item newArr.push(item) } }) return newArr }
执行结果:
let arr = [1, 2, 2, 'a', 'a'] uniqueArr(arr) // 调用 // 输出 [1, 2, "a"]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
利用对象属性名的唯一性对数组去重
解析
答案
执行结果:
The text was updated successfully, but these errors were encountered: