Yes, you can do that, in a variety of ways. Suppose you have:
var users = [{userID: 1, userName: robert}, {userID: 2, userName: daniel}];
To retrieve the userID and userName for Robert, you have access them via users[0].userID and users[0].userName.
If instead you want to retrieve them by users.userID[0] and users.userName[0], then you need to store it this way:
var users = {userID: [1, 2], userName: [robert, daniel]};
If you are asking how to transform the first form to the second, use this:
function transform(source) {
var result = {};
for (var i = 0; i < source.length; i++) {
for (property in source[i]) {
if (typeof result[property] == "undefined")
result[property] = [];
result[property].push(source[i][property]);
}
}
}
And use it this way:
var transformed_users = transform(users);
Do note that this transform function is specific to your data structure.
users[n]. Are you asking how to get all the ids and names?users.userIDandusers.userNameto get you more than one thing?users[0].userIDandusers[1].userID