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

数组合并方法总结 #38

Open
zlluGitHub opened this issue Oct 28, 2018 · 0 comments
Open

数组合并方法总结 #38

zlluGitHub opened this issue Oct 28, 2018 · 0 comments

Comments

@zlluGitHub
Copy link
Owner

1. concat 方法

var a=[1,2,3], b=[4,5,6];
var c=a.concat(b);
console.log(c);// 1,2,3,4,5,6
console.log(a);// 1,2,3 不改变本身

2. apply 方法

合并数组 arr1 和数组 arr2 ,使用 Array.prototype.push.apply(arr1,arr2) or arr1.push.apply(arr1,arr2);

var arr1=['a','b'];
var arr2=['c','d','e'];
Array.prototype.push.apply(arr1,arr2);
//或者
arr1.push.apply(arr1,arr2);
console.log(arr1) //['a','b','c','d','e']

3. 循环遍历

var arr1=['a','b'];
var arr2=['c','d','e'];
for(var i=0;i<arr2.length;i++){
   arr1.push(arr2[i]) 
}
console.log(arr1);//['a','b','c','d','e']
@zlluGitHub zlluGitHub changed the title 对象合并方法 数组合并方法总结 Oct 28, 2018
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