Tuesday, 3 December 2019

javascript forin and for off

https://alligator.io/js/for-of-for-in-loops/

let animals = ['🐔', '🐷', '🐑', '🐇'];let names = ['Gertrude', 'Henry', 'Melvin', 'Billy Bob'];
for (let animal of animals) {
 
// Random name for our animal
 
let nameIdx = Math.floor(Math.random() * names.length); console.log(`${names[nameIdx]} the ${animal}`);
}



let oldCar = {
 
make: 'Toyota',
 
model: 'Tercel',
 
year: '1996'
};
for (let key in oldCar) {
 
console.log(`${key} --> ${oldCar[key]}`);
}

No comments:

Post a Comment