Let’s say that I have a object that looks like this
var object = { id : 1, name : "Test"}
And I know that in jQuery I can make an each assuming that I have an array of this object example like this:
$.each(arrayOfObjects, function (i, value) {
this.id // gives me the id
this.name //gives me the name
});
Assuming that id and name are string parameters, how can I get the values??
UPDATE
I’m already modified the code, i just want to know if exit’s a way to accomplish something like this
var aux = 'id'
$.each(arrayOfObjects, function (i, value) {
this.aux // gives me the id
this+ aux
});
If I understood the question, you want to get the object’s keys as well as the values? You can loop over each object in the array to get the keys and values.
UPDATE: To use a string as a key in an object, you need to use
[].