'Is there any function which adds 1 to the array element? [closed]
I have a given array like this let arr1 = ['a','b','c'];
And I want output like this ['a1','b1','c1']
Which function should I use?
Solution 1:[1]
For this task, the map function is the best candidate. It generates a new array by applying the function given as argument to each element.
let arr1 = ['a','b','c'];
console.log(arr1.map(x=>`${x}1`));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rplantiko |
