js交错合并数组

2021-03-01 16:30

阅读:505

标签:lang   length   javascrip   java   filter   console   数组   class   for   

let arr1 = [1,2,3,4,5,6]
let arr2 = [‘1a‘,‘2a‘,‘3b‘,1]

let arr3 = [];
for(let i in arr1.length > arr2.length ? arr1 : arr2){
	if (arr1[i]) arr3[2*i] = arr1[i]
	if (arr2[i]) arr3[2*i+1] = arr2[i]
}
let arr4 = arr3.filter(e=>e)

console.log(arr4);

js交错合并数组

标签:lang   length   javascrip   java   filter   console   数组   class   for   

原文地址:https://www.cnblogs.com/China-Dream/p/14430387.html


评论


亲,登录后才可以留言!