return new array of modified elements js code example
Example 1: foreach and replace item based on condition
arr.forEach(function(part, index) {
this[index] = "hello world";
}, arr); // use arr as this
Example 2: forEach modify array JavaScript
arr.forEach(function(part, index) {
this[index] = "hello world";
}, arr); // use arr as this