最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Delete first element from each array in javascript - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 9

Use .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']];
发布评论

评论列表(0)

  1. 暂无评论