2

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?

1
  • 1
    yes, map is appropriate. Commented Sep 6, 2018 at 23:18

1 Answer 1

3

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
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.