javascript array flat
// flat(depth),
// depth is optional: how deep a nested array structure
// should be flattened.
// default value of depth is 1
const arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
const arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
const arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
arr4.flat(Infinity);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
Also in JavaScript:
- javascript get same elments from multiple arrays
- https.get module in nodejs
- js array delete last
- js takes a string of words and returns the highest scoring word.
- c# loop through json
- javascript generate random number
- onPress image react native
- js while
- vue get height of element ref
- define a media query in styled components
- Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
- js replace quotes
- how to multiple loop in javascript using for
- javascript function variable arguments
- cannot find name json angular 7
- javscript remove a property
- computed property name javascript
- javascript detect time on page
- not operator js
- javascript async await for x seconds
- httpclient post c# json
- warning Non-interactive elements should not be assigned mouse or keyboard event listeners jsx-a11y/no-noninteractive-element-interactions
- bullmq
- _.get alternative