Answers for "flatmap javascript"

1

flatmap javascript

var arr = [1, 2, 3, 4];

arr.flatMap(x => [x, x * 2]);
// is equivalent to
arr.reduce((acc, x) => acc.concat([x, x * 2]), []);
// [1, 2, 2, 4, 3, 6, 4, 8]
Posted by: Guest on May-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language