Skip to content
Advertisement

How to get odd or even lines from a two-dimensional array?

How to get odd or even lines from a two-dimensional array?

JavaScript

And write them into 1 or 2 new arrays. Need to get:

JavaScript

myData Array size unknown, maybe <5 , <6

Advertisement

Answer

You can use math. You know that there will be half even and half odd. You can use that and a loop to copy the values from the original array to the new arrays. Something like,

JavaScript

Outputs

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement