Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

flatten in js without lodash

const array1 = [ 1, 2, 3, [4, 5, 6, [7, 8, 9, [10]]]];
//flattened using es6 js
const flattenArray2 = array1.flat();
// result: [1, 2, 3, 4, 5, 6, [7, 8, 9, [10]]]
const flattenDeepArray2 = array1.flat(Infinity);
// result: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

//flattened using lodash
const _ = require('lodash');
const flattenArray1 = _.flatten(array1);
const flattenDeepArray1 = _.flattenDeep(array1);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to check if array is empty or not in javascript 
Javascript :: datatable hide columns 
Javascript :: fatal error: ineffective mark-compacts near heap limit allocation failed – javascript heap out of memory 
Javascript :: jquery image change on hover 
Javascript :: how to get current date in react js 
Javascript :: dotenv nodejs 
Javascript :: adding firebase to angular 
Javascript :: shadown reAct native 
Javascript :: traverse an array in javascript 
Javascript :: how to convert to one decimal place javascript 
Javascript :: lottie react 
Javascript :: immediate invoke function js 
Javascript :: javascript how to ceil number 
Javascript :: check change event in jquery 
Javascript :: react native elevation 
Javascript :: video preview javascript 
Javascript :: json rename key 
Javascript :: javascript ES6 destructure dynamic property name 
Javascript :: prop type for ref in react js 
Javascript :: js replace all symbols in string 
Javascript :: draw line in javascript 
Javascript :: get element by id in javascript 
Javascript :: js shortcut 
Javascript :: clear whitespace from object javascript 
Javascript :: javascript check if string is valid hex color 
Javascript :: Import file to mongodb database 
Javascript :: get ip address js 
Javascript :: yarn build react 
Javascript :: js add element to front of array 
Javascript :: formik stepper form 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =