Javascript Array reduce() collect property

Description

Javascript Array reduce() collect property

let primaryColors = [
    { color : 'red' },
    { color : 'yellow' },
    { color : 'blue' }
];

let previousColors = primaryColors.reduce( ( previous, primaryColor ) => {

    previous.push( primaryColor.color );
    return previous;

}, [] );//from w ww  . ja v a2  s.c o m

console.log( previousColors );



PreviousNext

Related