0

I have an array of array created from a for-loop which is incremented by 2. As a result the end result array looks like this:

(3) [Array(2), empty, Array(2)]
0: (2) ["A", 2]
2: (2) ["B", 4]
length: 3
__proto__: Array(0)

What's the best way to remove the empty array ?

 var arr = [];
    
   var z = 0;
    for (var i = 0; i < props.data.length;  i += 2) {
    
     arr[i] =  [props.data[i][1], parseFloat(props.data[i+1][1]), ] 

    }
Ibra
  • 912
  • 1
  • 12
  • 31
  • 2
    _The best way_ would probably be not to create these empty entries in the first place? Maybe by using `arr.push(x);` instead of `arr[i] = x;`? – blex May 17 '21 at 23:25
  • 1
    https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript. I think this will help – AbdElzaher May 17 '21 at 23:29
  • I updated my question and currently reviewing other answers. Thanks for the suggestions :) – Ibra May 17 '21 at 23:56

0 Answers0