0

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?

enter image description here

4
  • stackoverflow.com/questions/966225/… Commented Aug 22, 2014 at 8:26
  • 1
    Yes, it is certainly possible. Commented Aug 22, 2014 at 8:27
  • You could build it from the ground up. But you could start with DataTables Commented Aug 22, 2014 at 8:29
  • @hindmost, of course I have tried. I didn't write the code in my question because I don't want my code to influence other answers. Commented Aug 22, 2014 at 9:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.