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

2 Answers 2

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 comment 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);

Sign up to request clarification or add additional context in comments.

1 Comment

You can also use .shift() instead of .splice(0,1).
4

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']];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.