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]

4.5
4
Katruje 85 points

                                    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]

4.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
flatten an array flat() in js flatten array of arrays javascript flat array js js flat method array flatten javascript flatter array of arrays javascript why flatten an array array flat javascript flatten array of array js array.flat in javascript js array flat node support how to flatten array javascript javascript flat array js flat arrays how to use flat in javascript js array.flat flatten a javascript array flatten array in array javascript what does .flat do in javascript flat an array js js flatArray javascript array flate array.flat js flat js array array.flatten how can I flatten a array in javascript? how to flatten array flatern js array how can I flatten array in javascript? array flatten node js flatten array js flat arr javascript flat flat array javascript .flat javascript js array flat flat out an array how to flatten array of arrays javascript js array flatten flatten the array javascript array flat js flatten function javascript flatten arr js flat function javascript javascript make one array of arrays flatten array in javascript flat infinity in javascript array.flat flatten infinite javasripts node js array flatten es6 nested array flatten the array in js flatten a array javascript flat in Js nested array to single array typescript flatten a array of arrys js flat() in javascript flat an array in js js flatten array flat() javascript array flat mdn flatten nested array javascript flatten l'array js .flat js array of array to array nested array to plain array javascript flatten raay in js flat arrqay flat array flatten array js flatten array how to flat an array in javascript without using flat function js flatten array of array to array flatten arrays convert nested array to single array javascript javascript convert array of arrays to array js flat array array flat js flatten list of lists flatten array of arrays js flat flatten array in js node flatten array js flatten nested array javascript flatten array flatten array javascript javascript array flat javascript flatten javascript array flatten
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source