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

数组合并 #83

Open
Sunny-117 opened this issue Nov 3, 2022 · 2 comments
Open

数组合并 #83

Sunny-117 opened this issue Nov 3, 2022 · 2 comments

Comments

@Sunny-117
Copy link
Owner

let arr1 = ["A1", "A2", "B1", "B2", "C1", "C2"]
let arr2 = ["A", "B", "C"];
// res=['A1', 'A2', 'A', 'B1', 'B2', 'B', 'C1', 'C2', 'C']
@veneno-o
Copy link
Contributor

veneno-o commented Mar 13, 2023

console.log([...new Set(arr1.concat(arr2))])

@kangkang123269
Copy link

  1. set
let arr1 = [1, 2, 3];
let arr2 = [3, 4, 5];
let merged = [...new Set([...arr1,...arr2])];
console.log(merged); // 输出:[1 ,2 ,3 ,4 ,5]
  1. filter
let arr1 = [1, 2, 3];
let arr2 = [3, 4, 5];
let merged = arr1.concat(arr2).filter((item,index,arr) => {
    return arr.indexOf(item) === index;
});
console.log(merged); // 输出:[1 ,2 ,3 ,4 ,5]

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

3 participants