Skip to content
New issue

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

《JavaScript专题之数组去重》勘误 Thanks MR-YUZL #212

Open
MR-YUZL opened this issue Jun 2, 2021 · 2 comments
Open

《JavaScript专题之数组去重》勘误 Thanks MR-YUZL #212

MR-YUZL opened this issue Jun 2, 2021 · 2 comments

Comments

@MR-YUZL
Copy link

MR-YUZL commented Jun 2, 2021

image

键值对去重,正则会被JSON.stringify转成{},导致/a/和/b/没有区别,去重之后只会保留一个正则

image

@mqyqingfeng
Copy link
Owner

@MR-YUZL 非常感谢你的指正,这里确实存在问题,相关的文章已引用更正

@mqyqingfeng mqyqingfeng changed the title 正则去重出错 《JavaScript专题之数组去重》勘误 Thanks MR-YUZL Nov 14, 2021
@fefuns
Copy link

fefuns commented Mar 12, 2022

function unique(array) {
    var obj = {};
    return array.filter(function (item, index, array) {
        console.log(typeof item + item + JSON.stringify(item))
        return obj.hasOwnProperty(typeof item + item + JSON.stringify(item)) ? false : (obj[typeof item + item + JSON.stringify(item)] = true)
    })
}
改成这样可以解决你说的正则不能去重的问题吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants