Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Flatten a multidimension array

// ES5 version
let flattened = [[1, 2], [3, 4], [5, 6]].reduce(function (acc, curVal) {
  return acc.concat(curVal)
}, []);

// ES6 version
let flattened = [[1, 2], [3, 4], [5, 6]].reduce((acc, curVal) => acc.concat(curVal), []);

console.log(flattened); // [1,2,3,4,5,6]
Comment

PREVIOUS NEXT
Code Example
Javascript :: move element onclick javascript 
Javascript :: js fetch 
Javascript :: index of 
Javascript :: storybook react router 
Javascript :: context api react 
Javascript :: get index vanilla js 
Javascript :: without refresh update url in js 
Javascript :: operator to return specific data of a mongodb query 
Javascript :: js substr 
Javascript :: how to get a due date from current date in javascript 
Javascript :: context hook 
Javascript :: mongoose find multiple conditions 
Javascript :: javascript check date is greater than today 
Javascript :: node.js check if a remote URL exists 
Javascript :: The element.parentNode Property 
Javascript :: react router redirect with query params 
Javascript :: javascript how to remove the last character of the string 
Javascript :: export app react native 
Javascript :: global axios vue 2 
Javascript :: how to use if else inside jsx in react 
Javascript :: play notification sound on chat js 
Javascript :: javascript create json object from array 
Javascript :: javascript add element to serialized form array 
Javascript :: setimmediate 
Javascript :: javascript array clear 
Javascript :: node package.json type module 
Javascript :: google geocode nodejs 
Javascript :: upload and send file to axios multipart 
Javascript :: javascript remove last charter stings 
Javascript :: nodejs heap usage 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =