Reputation: 39
noob question... As the title, I would add for example 5 to each element of an array like this
array = [3,6,23,5,43]
Result would be newarray = [8,11,28,10,48]
Maybe with map operator?
Upvotes: 2
Views: 52
Reputation: 39254
You can do a map like this:
var result = array.map(x => x + 5)
Or in more traditional syntax:
var result = array.map(function(x) {
return x + 5
});
Upvotes: 3