admin管理员组文章数量:1356952
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
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
Share Improve this question edited Apr 28, 2017 at 7:13 Suren Srapyan 68.7k14 gold badges125 silver badges117 bronze badges asked Apr 28, 2017 at 7:11 VahidVahid 1191 gold badge2 silver badges14 bronze badges2 Answers
Reset to default 9Use .forEach to loop over the nested arrays and then .splice them. 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 ment you can also use .shift() function to remove the first item.
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']];
本文标签: Delete first element from each array in javascriptStack Overflow
版权声明:本文标题:Delete first element from each array in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744034940a2579594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论