Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

iterate over array of objects javascript

// Create a new array based on the original but without modifying it

const myArray = [{x:100}, {x:200}, {x:300}];

const newArray= myArray.map(element => {
    return {
        ...element,
        x: element.x * 2
    };
});

console.log(myArray); // [100, 200, 300]
console.log(newArray); // [200, 400, 600]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #iterate #array #objects #javascript
ADD COMMENT
Topic
Name
8+6 =