简体   繁体   English

从JavaScript中的每个数组删除第一个元素

[英]Delete first element from each array in javascript

I have a multi dimensional array like this. 我有一个这样的多维数组。

 var myArray = [['aaa','1','2.33','44'],['bbb','1','2.33','44'],['ccc','1','2.33','44']]

I want to remove all the first element to get a result like this. 我想删除所有第一个元素以得到这样的结果。

var myArray = [['1','2.33','44'],['1','2.33','44'],['1','2.33','44']]

Please Help me. 请帮我。 Thanks 谢谢

Use .forEach to loop over the nested arrays and then .splice them. 使用.forEach遍历嵌套数组,然后.splice它们。 Splice will remove the first item in the nested array and effect the current array. 拼接将删除嵌套数组中的第一项并影响当前数组。

 var myArray = [['aaa','1','2.33','44'],['bbb','1','2.33','44'],['ccc','1','2.33','44']]; myArray.forEach(array => array.splice(0,1)); console.log(myArray); 

Base on the comment you can also use .shift() function to remove the first item. 根据注释,您还可以使用.shift()函数删除第一项。

 var myArray = [['aaa','1','2.33','44'],['bbb','1','2.33','44'],['ccc','1','2.33','44']]; myArray.forEach(array => array.shift()); console.log(myArray); 

You can try this 你可以试试这个

 var myArray = [['aaa','1','2.33','44'],['bbb','1','2.33','44'],['ccc','1','2.33','44']]; var done = function(){ console.log(myArray); }; myArray.forEach(function(array){ array.splice(0,1); done(); }); 

Output 输出量

[['1','2.33','44'],['1','2.33','44'],['1','2.33','44']];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM