I have an array object in javascript. I would to select a particular field from all the rows of the object.
I have an object like
var sample = {
[Name:"a",Age:1],
[Name:"b",Age:2],
[Name:"c",Age:3]
}
I would like to get an output of only Names as ["a","b","c"] without looping over sample object.
How can I select one or two fields using jlinq? or any other plugin?
Thanks a lot.
You’ve got your definition the wrong way round. Instead of having an object containing 3 arrays, you want an array of objects.
like this:
Then you can do:
or to get all your names as per your example:
But, without looping im not sure how you would get any number of values…. why no looping?
Just say you do loop, here’s how you would do it:
or with jQuery (which is still looping)