[Solved] HOw to access all the colors from within all the color arrays?


You can use the map function for the array of objects and then a for loop for the inner property “color” of each object.

var fruits = [{
    name: "apple",
    color: ["green", "red"]
}, {
    name: "banana",
    color: ["yellow"]
}];

var colors = [];

fruits.map(function(fruit) {
    for (var i = 0; i <  fruit.color.length; i++) {
        colors.push(fruit.color[i]);
    }
});

9

solved HOw to access all the colors from within all the color arrays?