There are fixed three columns in it. The rows are added dynamically and may go up-to few thousands also.
I should also be able to iterate through the array and filter Id & Values based on level.
Is this possible ? How?
There are fixed three columns in it. The rows are added dynamically and may go up-to few thousands also.
I should also be able to iterate through the array and filter Id & Values based on level.
Is this possible ? How?
Arrays of Arrays are easy.
[[1, 234,'Apple'],[2,23,'Sunday'], ....]
To add something to the array, push use push
. To iterate forEach
. filter
is not yet in the JS standard, but here is a polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
I suggest for your problem to look at not building an Array of Arrays, but model each row as a JS object:
{level: 1, id: 234, value: 'Apple'}
that way you can write more semantic code like
myObjectList.filter(function(obj){ return obj.level > 1 })
rather than using array indexes everywhere.
In general if you ant get an idea what you can do with JS built-ins like Array, check the JS reference at the Mozilla Developer Network. Its pretty good and has lots of examples for each Array function like forEach
or find
, or filter
.