Seeking a more efficient method to adjust the length of an array and its elements. Consider the following initial array:
var arr = [["Name", "Age", "Lightsaber Color"], ["Luke Skywalker", "22", "Green"], ["Yoda", "900", "Green"], ["Obi Wan Kenobi", "59", "Blue"]]
The desired output should be:
var arr = [["Name", "Age"], ["Luke Skywalker", "22"], ["Yoda", "900"]]
I have implemented some code but would like to ensure optimal efficiency in adjusting the size of nested arrays. Here is what I currently 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)
I am particularly interested in optimizing the for loop as I anticipate working with larger datasets. Appreciate your insights!