You may find the following article interesting
Essentially, the (jQuery) object returned by the jQuery $()
function has a bunch of properties, which include one for each element that matches the selector, with the property name being a numeric "index"
For example, given the following HTML
<p>Hello, World!</p>
<p>I'm feeling fine today</p>
<p>How are you?</p>
and the selector
$('p');
the object returned will look as follows
({length:3, 0:{}, 1:{}, 2:{}})
Using the .get()
command, you can access matched elements and operate on them accordingly. Following with the example
$(function () {
var p = $('p').get();
for (var prop in p)
alert(prop + ' ' + p[prop].innerHTML);
});
or alternatively, knowing how the returned object is structured
$(function () {
var p = $('p');
for (var i=0; i< p.length; i++)
alert(i + ' ' + p[i].innerHTML);
});
will alert
0 Hello, World!
1 I'm feeling fine today
2 How are you?
I know that I have not answered your question directly, but thought that it may be useful to provide insight into how jQuery works.
I think what you need in order to answer your question is either
a simple array, as demonstrated by Tomas Lycken's answer. This seems to best fit what you are asking for
var mySimpleArray = ['a','b','c'];
an array of objects, with each object having an 'index' and 'name'. I'll make the assumption here that 'index' is implied to be be any number that you want to assign and does not imply an ordinal position
var myObjectArray = [{ index: 5, name: 'a' },{ index: 22, name: 'b'},{ index: 55, name: 'c'}];