Is there any equivalent metod to make like an php mysql_fetch_array while loop in js?
in php you can do:
<?php
while ($row = mysql_fetch_array($result)) {
echo "my name is " . $row['name'] . " and i'm " . $row['age'] . " yeas old";
}
?>
i have this object/array:
function fetch_array(arr) {
// My magic fn that dose not work well, b/c it change the orginal refence
return arr.shift();
}
var result = [{
name: "Bob",
age: 12
}, {
name: "Jim",
age: 18
}]
// And want to do:
while (row = fetch_array(result)) {
alert("my name is " + row["name"] + " And I'm " + row['age'] + " years old");
}
// returns zero :( dont want that
console.log(result.length);