I have the following array:
>>> var cars = new Array;
undefined
>>> cars[5] = 'Volvo';
"Volvo"
>>> cars[10] = 'Honda';
"Honda"
>>> cars
[undefined, undefined, undefined, undefined, undefined, "Volvo", undefined, undefined, undefined, undefined, "Honda"]
>>> cars.length
11
Is there a way to get new array out of cars
that is not sparse - like ['Volvo', 'Honda']
. Actually in my case even the order of the values would not matter.
Of course, I can do it with a loop but I'm looking for more elegant solution. jQuery
is also an option!