I need to take an array of objects like this...
var users = [{
id: 0,
full_name: 'None',
gravatar_url: 'http://gravatar.com/avatar/31b64e4876d603ce78e04102c67d6144?s=80'
},
{
id: 1,
full_name: 'Jason Davis',
gravatar_url: 'http://gravatar.com/avatar/31b64e4876d603ce78e04102c67d6144?s=80'
},
{
id: 2,
full_name: 'Eric',
gravatar_url: 'http://gravatar.com/avatar/31b64e4876d603ce78e04102c67d6144?s=80'
}];
and build these 3 arrays from the objects above. The array key number should match on all. So array with full_name = Jason Davis should match array key 1 on the ID array
THe idea is I should be able to rebuild the objects above by doing this...
id[1]
full_name[1]
gravatar_url[1]
these above should all map to the object with user Jason Davis.
var id = [0, 1, 2];
var full_name = [
'None',
'Jason Davis',
'Eric'
];
var gravatar_url = [
'http://gravatar.com/avatar/31b64e4876d603ce78e04102c67d6144?s=80',
'http://gravatar.com/avatar/31b64e4876d603ce78e04102c67d6144?s=80',
'http://gravatar.com/avatar/31b64e4876d603ce78e04102c67d6144?s=80'
];
The Reasoning
I am building this using a popover selector library...
The library only accepts a single array of data which is shown as each item. In this image it is the user name.
(to clarify, the image above I added the thumbnail images into the DOM manually, the library does not accept a 2nd data on each item yet)
By doing what my question ask, I can assign the user image to another array
The library builds the items HTML like this...
for (var i in this.options.items) {
var itemElement = $(this.options.templates.pickerItem);
itemElement.find('i').html(this.options.items[i]);
itemElement.data('pickerValue', this.options.items[i])
.on('click.picker', itemClickFn);
this.picker.find('.picker-items').append(itemElement);
}
It calls this.options.items[i]
to get the name. If I have my own 2nd array of images I can use the key to show the correct user image with its name!