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数组去重,数组交叉对比 #32

Open
zhn4 opened this issue Mar 15, 2018 · 0 comments
Open

javascript数组去重,数组交叉对比 #32

zhn4 opened this issue Mar 15, 2018 · 0 comments

Comments

@zhn4
Copy link
Owner

zhn4 commented Mar 15, 2018

javascript数组去重,数组交叉对比
demo:http://jsbin.com/wofupuyiqe/edit?js,console,output

var arr1 = [1,2,3,4,5,34,34,4,5456,56,45,'happt','end']

var arr2 = [2,3,88,44,'end']

var results = []

arr1.map((data, i) => {
  arr2.map((datas, j) => {
    if(data === datas) {
      results.push(data)
    }
  })
})
// 数组交叉对比,arr1内遍历arr2对比

console.log(results)

var arr3 = [1,2,3,4,65,4,3,32,3,4,5,3,3,2,5,435,45,45,4]
var arr4 = []
arr3.map((data, i) => {
  if(arr4.indexOf(data) === -1) {
    arr4.push(data)
  }
})
// indexOf判断空数组arr4内是否存在元素,不存在就反回-1,把元素推进空数组arr4

console.log(arr4)
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

1 participant