I am trying to find an efficient way of changing the length of an array and the elements within the array. For example, if I have
var arr = [["Name", "Age", "Lightsaber Color"], ["Luke Skywalker", "22", "Green"], ["Yoda", "900", "Green"], ["Obi Wan Kenobi", "59", "Blue"]]
I want to end up with
var arr = [["Name", "Age"], ["Luke Skywalker", "22"], ["Yoda", "900"]]
I have written some code to do this, but I want to ensure that the way I am changing the length of the nested arrays (for lack of a better term) is as efficient as possible.
I have:
var arr = [["Name", "Age", "Lightsaber Color"], ["Luke Skywalker", "22", "Green"], ["Yoda", "900", "Green"], ["Obi Wan Kenobi", "59", "Blue"]]
arr.length = 3; // Removes the Obi Wan entry
console.log(arr);
for(var i = 0; i < arr.length; i++){
arr[i].length = 2 // Removes lightsaber color
};
console.log(arr)
The code I'm wanting to hopefully optimize is the for loop. I'll be working with much larger datasets. Thanks