mardi 3 mars 2015

How to loop through array and find if key


So basiclly I want o loop through an error (what i already did) and print the other key



var planet = "sun";
var planets = [{
type: "sun",
desc: "sun"
}, {
type: "moon",
desc: "moon"}];

var pln = planets.length;
for (var i = 0; i < pln; i++) {
console.log(planets[i]);
}


How can i I find out if the var planet is in the array planets and print out the description from that key if so?





Aucun commentaire:

Enregistrer un commentaire