Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to flatten array with reduce in javascript

let flattened = [[0, 1], [2, 3], [4, 5]].reduce(
  function(accumulator, currentValue) {
    return accumulator.concat(currentValue)
  },
  []
)
// flattened is [0, 1, 2, 3, 4, 5]
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #flatten #array #reduce #javascript
ADD COMMENT
Topic
Name
8+5 =