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

数组去重 #23

Open
xxxgitone opened this issue Oct 4, 2017 · 0 comments
Open

数组去重 #23

xxxgitone opened this issue Oct 4, 2017 · 0 comments

Comments

@xxxgitone
Copy link
Owner

xxxgitone commented Oct 4, 2017

收集几种数组去重的方法

indeOf

var array = [1, 1, '1', 2]

function unique(array) {
    var res = []
    for (var i = 0, len = array.length; i < len; i++) {
        var current = array[i]
        if (res.indexOf(current) === -1) {
            res.push(current)
        }
    }
    return res
}

console.log(unique(array))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant