在线等,挺急的!如何用空数组,补齐数组数量十分感谢

test=
[
["qwe","1"],
["ewq","2"],
["aaa","4"],
]
我想让数组数量保持在四个,有缺就补空数组,并且要照数组内的数字去补,却哪里补哪里
补完要像这样
test=
[
["qwe","1"],
["ewq","2"],
["",""],
["aaa","4"],
]
该如何实现这需求?
智慧大石
浏览 265回答 2
2回答

江户川乱折腾

lettest=[["qwe","1"],["ewq","2"],["aaa","4"],]functionsetArr(test){for(leti=0;i

翻翻过去那场雪

test.reduce((acc,cur,i)=>{while(cur[1]-1!=i){acc.push(['','']);i++}acc.push(cur);returnacc;},[])前提默认原数组是按循序(1,2,3...)排列的
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript