I have [3, 16, 120]. when I do [3, 16, 120].map(mapper), I want to achieve, for example [4,5, 17,18, 121,122] i.e. each element map to n
[3, 16, 120]
[3, 16, 120].map(mapper)
[4,5, 17,18, 121,122]
Using Array.prototype.flat():
const doubled = [3, 16, 120].map(item => [item + 1, item + 2]).flat(); console.log(doubled)
Fair warning – not a standard method to this date (posted 12/2018).