Is there a way to loop over the following variable and print out it's values (0,1,2) i've tried to run forEach on it, but i get an error that forEach is not a function.
let colors = {
RED: 0,
GREEN: 1,
BLUE: 2 };
Is there a way to loop over the following variable and print out it's values (0,1,2) i've tried to run forEach on it, but i get an error that forEach is not a function.
let colors = {
RED: 0,
GREEN: 1,
BLUE: 2 };
var colorKeys = Object.keys(colors);
for(int i = 0; i < colorKeys.length; i++){
console.log(colors[colorKeys[i]]);
}
Try it
let colors = {
RED: 0,
GREEN: 1,
BLUE: 2 };
for(let i in colors){
console.log(colors[i]);
}