0
var row = [["1", ".", "3", '1', 1], ["1", ".", "3", '4', 5], ["2", "7", "5", '4', 0]];

var newArray = row.splice([1][2], 1);

I am trying to take only the third element from the second subarray.

1
  • Welcome to SO! Do you want splice to actually remove the item from the array permanently, or do you just want to index into the array to retrieve an item? Either way, the index needs to be on the row array: row[1].splice(2, 1). Thanks for clarifying. Commented Mar 20, 2020 at 21:49

2 Answers 2

1

Select the second element before you call splice:

var row = [["1", ".", "3", '1', 1], ["1", ".", "3", '4', 5], ["2", "7", "5", '4', 0]];

var newArray = row[1].splice(2, 1);
Sign up to request clarification or add additional context in comments.

Comments

0

var row = [["1", ".", "3", '1', 1], ["1", ".", "3", '4', 5], ["2", "7", "5", '4', 0]];

var newArray = row[1].splice(2,1);
   


console.log(newArray);

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.