I have an array in Javascript:
var array = new array();
array[0] = "apples";
array[1] = "oranges";
array[2] = "pears";
In PHP, with a given array, I can use the following to loop through an array, and break up the keys and values:
foreach ($array as $key => $value) {
echo("Key is $key and Value is $value");
}
How can I do this in Javascript? I'm aware of:
for (x in array){
// Do something with x.
}
But I've found nothing that will replicate the php style foreach. Is it possible to concisely achieve something similar in Javascript? (I'm also using jQuery, if something can be done in jQuery).