Hey this is my first question and I\'m just finding my way with JS. I have an array which is set, I want to loop through it and divide each value by 100, then print the output t
The non-ES6 code might read like this. map returns a new array where each element has been changed by the function. It's up to you whether you want a new array, or whether you use a for
loop to change the elements of the existing array.
var example = [5, 10, 15, 20];
Example 1
var out = example.map(function (el) {
return el / 100;
});
console.log(out); // [ 0.05, 0.1, 0.15, 0.2 ]
Example 2
for (var i = 0, l = example.length; i < l; i++) {
example[i] = example[i] / 100;
}
console.log(example);