From 15bb1c7953401bc3ad7343718b654cd6fd6383b4 Mon Sep 17 00:00:00 2001 From: Miles Edwards <97187572+M-Edwards7@users.noreply.github.com> Date: Fri, 13 Jun 2025 22:28:35 -0400 Subject: [PATCH 1/9] [Term Entry] JavaScript Arrays: flat() #7084 - Initial commit - Create flat folder and flat.md file - Add template from the term entry template file --- .../concepts/arrays/terms/flat/flat.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 content/javascript/concepts/arrays/terms/flat/flat.md diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md new file mode 100644 index 00000000000..1805007c9db --- /dev/null +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -0,0 +1,44 @@ +--- +Title: 'The Title' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'A subject name' + - 'A second subject name' + - 'An nth subject name' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'A tag' + - 'A second tag' + - 'An nth tag' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'learn-example-course' + - 'paths/example-path' +--- + +[A brief definition - make sure first mention of term is in **bold**.] + +## Syntax + +[Text, code, images, parameters, etc. about the syntax] + +## Example + +[Text, code, images, etc. about example 1] + +## Codebyte Example (if applicable) + +We can currently support: + +- Python +- JavaScript +- Ruby +- C++ +- C# +- Go +- PHP + +See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details! + +```codebyte/js +# Example runnable code block. +console.log('Hello, World!'); +``` \ No newline at end of file From c839b31825738e15743e39d005fe0c4401d72ccb Mon Sep 17 00:00:00 2001 From: Miles Edwards <97187572+M-Edwards7@users.noreply.github.com> Date: Sat, 14 Jun 2025 23:56:35 -0400 Subject: [PATCH 2/9] [Term Entry] JavaScript Arrays: flat() #7084 - add comprehensive guide with definitions and examples - add link to codecademy array docs - complete first draft of flat.md --- .../concepts/arrays/terms/flat/flat.md | 143 ++++++++++++++---- 1 file changed, 113 insertions(+), 30 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index 1805007c9db..0a1bfb16376 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -1,44 +1,127 @@ --- -Title: 'The Title' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - - 'A subject name' - - 'A second subject name' - - 'An nth subject name' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! - - 'A tag' - - 'A second tag' - - 'An nth tag' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first - - 'learn-example-course' - - 'paths/example-path' +Title: 'flat()' +Description: 'Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth' +Subjects: + - 'Web Development' + - 'Computer Science' +Tags: + - 'Arrays' + - 'Methods' + +CatalogContent: + - 'introduction-to-javascript' + - 'paths/front-end-engineer-career-path' --- -[A brief definition - make sure first mention of term is in **bold**.] +The **`flat()`** method creates a new [array](https://www.codecademy.com/resources/docs/javascript/arrays) with all sub-array elements recursively concatenated up to the specified depth. It is a non-mutating method, meaning it returns a new array, leaving the original unchanged. ## Syntax -[Text, code, images, parameters, etc. about the syntax] +```js + array.flat(); + array.flat(depth); +``` +The optional `depth` parameter specifies how many levels of nested arrays to flatten. +If omitted, defaults to `1`. + +If set to `Infinity`, the method flattens all nested sub-arrays, regardless of their depth. + + +## Example 1 + +This example shows the use of `flat()` with the default depth of 1: + +```js +const arr = [1, 2, [3, 4]]; +console.log(arr.flat()); +``` + +The output of this code is: + +```shell +[1, 2, 3, 4] +``` + +`arr.flat()` flattens one level deep, so the nested array `[3, 4]` is unpacked into the main array. + +## Example 2 + +This example shows the use of `flat()` with the default depth of 1, with multiple layers of nested sub-arrays: + +```js +const arr = [1, 2, 3, [4, 5, [6, 7]]]; +console.log(arr.flat()); +``` + +The output of this code is: + +```shell +[1, 2, 3, 4, 5, [6, 7]] +``` + +`arr.flat()` flattens the array one level deep. It unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. However, the inner array `[6, 7]` remains nested because it is at a deeper level. + +## Example 3 + +This example shows the use of `flat()` with a depth of 2, applied to an array with multiple layers of nested sub-arrays: +```js +const arr = [1, 2, 3, [4, 5, [6, 7]]]; +console.log(arr.flat(2)); +``` + +The output of this code is: + +```shell +[1, 2, 3, 4, 5, 6, 7] +``` + +`arr.flat(2)` flattens the array two levels deep. First, it unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. Then, the inner array `[6, 7]` is unpacked, resulting in a fully flattened array with no nested sub-arrays. + +## Example 4 + +This example shows the use of `flat()` with a depth of `Infinity`, which fully flattens an array no matter how deeply nested its sub-arrays are: + +```js +const arr = [1, [2, [3, [4, [5]]]]]; +console.log(arr.flat(Infinity)); +``` + +The output of this code is: + +```shell +[1, 2, 3, 4, 5] +``` + +`arr.flat(Infinity)` recursively flattens the array to its deepest level. All nested sub-arrays, no matter how deeply they are nested, are unpacked into a single flat array. This is useful when the depth of nesting is unknown or highly variable. + +## Example 5 + +This example shows the use of `flat()` on sparse arrays: + +```js +const arr = [1, 2, , [4, , 6], 7]; +console.log(arr.flat()); +``` + +The output of the code is: -## Example +```shell +[1, 2, 4, 6, 7] +``` -[Text, code, images, etc. about example 1] +`flat()` removes the holes (empty slots) in the array whilst flattening. Even if the array is 1-level deep (no nested arrays) the sparse elements are still removed. -## Codebyte Example (if applicable) +## Non-array elements -We can currently support: +The `flat()` method only flattens nested arrays. Elements that are not arrays remain the same: -- Python -- JavaScript -- Ruby -- C++ -- C# -- Go -- PHP +```js +const arr = [1, 'hello', [2, 3], { a: 4 }]; +console.log(arr.flat()); +``` -See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details! +The output of the code is: -```codebyte/js -# Example runnable code block. -console.log('Hello, World!'); +```shell +[1, "hello", 2, 3, { a: 4 }] ``` \ No newline at end of file From acdd7b89c326cb7a0774e286ad56b4a77232b6fd Mon Sep 17 00:00:00 2001 From: Miles Edwards <97187572+M-Edwards7@users.noreply.github.com> Date: Sun, 15 Jun 2025 02:14:54 -0400 Subject: [PATCH 3/9] [Term Entry] JavaScript Arrays: flat() #7084 - correct typos - add more descriptive example subtitles to enhance user experience finding information quickly --- .../concepts/arrays/terms/flat/flat.md | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index 0a1bfb16376..58c9c8f28e1 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -19,17 +19,17 @@ The **`flat()`** method creates a new [array](https://www.codecademy.com/resourc ```js array.flat(); - array.flat(depth); + array.flat([depth]); ``` -The optional `depth` parameter specifies how many levels of nested arrays to flatten. -If omitted, defaults to `1`. -If set to `Infinity`, the method flattens all nested sub-arrays, regardless of their depth. +The ***optional*** `depth` parameter specifies how many levels of nested arrays to flatten. +If omitted, it defaults to `1`. +If set to `Infinity`, the method flattens all nested sub-arrays, regardless of their depth. -## Example 1 +## Example 1: Default -This example shows the use of `flat()` with the default depth of 1: +This example demonstrates using `flat()` with the default depth of 1: ```js const arr = [1, 2, [3, 4]]; @@ -44,9 +44,9 @@ The output of this code is: `arr.flat()` flattens one level deep, so the nested array `[3, 4]` is unpacked into the main array. -## Example 2 +## Example 2: Default with nested sub-arrays -This example shows the use of `flat()` with the default depth of 1, with multiple layers of nested sub-arrays: +This example demonstrates using `flat()` with the default depth of 1, with multiple layers of nested sub-arrays: ```js const arr = [1, 2, 3, [4, 5, [6, 7]]]; @@ -61,9 +61,10 @@ The output of this code is: `arr.flat()` flattens the array one level deep. It unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. However, the inner array `[6, 7]` remains nested because it is at a deeper level. -## Example 3 +## Example 3: Using a depth param + +This example demonstrates using `flat()` with a depth of 2, applied to an array with multiple layers of nested sub-arrays: -This example shows the use of `flat()` with a depth of 2, applied to an array with multiple layers of nested sub-arrays: ```js const arr = [1, 2, 3, [4, 5, [6, 7]]]; console.log(arr.flat(2)); @@ -77,9 +78,9 @@ The output of this code is: `arr.flat(2)` flattens the array two levels deep. First, it unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. Then, the inner array `[6, 7]` is unpacked, resulting in a fully flattened array with no nested sub-arrays. -## Example 4 +## Example 4: Infinity -This example shows the use of `flat()` with a depth of `Infinity`, which fully flattens an array no matter how deeply nested its sub-arrays are: +This example demonstrates using `flat()` with a depth of `Infinity`, which fully flattens an array no matter how deeply nested its sub-arrays are: ```js const arr = [1, [2, [3, [4, [5]]]]]; @@ -94,9 +95,9 @@ The output of this code is: `arr.flat(Infinity)` recursively flattens the array to its deepest level. All nested sub-arrays, no matter how deeply they are nested, are unpacked into a single flat array. This is useful when the depth of nesting is unknown or highly variable. -## Example 5 +## Example 5: Sparse arrays -This example shows the use of `flat()` on sparse arrays: +This example demonstrates using `flat()` on sparse arrays: ```js const arr = [1, 2, , [4, , 6], 7]; @@ -111,7 +112,7 @@ The output of the code is: `flat()` removes the holes (empty slots) in the array whilst flattening. Even if the array is 1-level deep (no nested arrays) the sparse elements are still removed. -## Non-array elements +## Example 6: Non-array elements The `flat()` method only flattens nested arrays. Elements that are not arrays remain the same: From 934eb33e53140a2a9b2a33f985dc27e1c2718adc Mon Sep 17 00:00:00 2001 From: Miles Edwards <97187572+M-Edwards7@users.noreply.github.com> Date: Sun, 15 Jun 2025 03:48:21 -0400 Subject: [PATCH 4/9] [Term Entry] JavaScript Arrays: flat() #7084 - add a newline at the end of the file to solve the failed linting test --- content/javascript/concepts/arrays/terms/flat/flat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index 58c9c8f28e1..fb8bb740ad0 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -125,4 +125,4 @@ The output of the code is: ```shell [1, "hello", 2, 3, { a: 4 }] -``` \ No newline at end of file +``` From 202d4ce2f7c020fbea0009b0b7a68c0b4c4e984b Mon Sep 17 00:00:00 2001 From: Miles Edwards <97187572+M-Edwards7@users.noreply.github.com> Date: Sun, 15 Jun 2025 04:09:33 -0400 Subject: [PATCH 5/9] [Term Entry] JavaScript Arrays: flat() - Fix formatting using prettier --- content/javascript/concepts/arrays/terms/flat/flat.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index fb8bb740ad0..673f3dfdae1 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -1,7 +1,7 @@ --- Title: 'flat()' Description: 'Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth' -Subjects: +Subjects: - 'Web Development' - 'Computer Science' Tags: @@ -18,12 +18,12 @@ The **`flat()`** method creates a new [array](https://www.codecademy.com/resourc ## Syntax ```js - array.flat(); - array.flat([depth]); +array.flat(); +array.flat([depth]); ``` -The ***optional*** `depth` parameter specifies how many levels of nested arrays to flatten. -If omitted, it defaults to `1`. +The **_optional_** `depth` parameter specifies how many levels of nested arrays to flatten. +If omitted, it defaults to `1`. If set to `Infinity`, the method flattens all nested sub-arrays, regardless of their depth. From 192296731c522a9717e001788c934b5e1bcc78eb Mon Sep 17 00:00:00 2001 From: Miles Edwards <97187572+M-Edwards7@users.noreply.github.com> Date: Wed, 18 Jun 2025 03:05:50 -0400 Subject: [PATCH 6/9] [Term Entry] JavaScript Arrays: flat() #7084 - Added a codebyte example --- content/javascript/concepts/arrays/terms/flat/flat.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index 673f3dfdae1..aa253915859 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -126,3 +126,14 @@ The output of the code is: ```shell [1, "hello", 2, 3, { a: 4 }] ``` + +## Codebyte Example + +The following code demonstrates how different `.flat()` depths affect an array: + +```codebyte/js +const arr = [1, 'hello', [2, 3, [4, [5, 'world']]], { a: 4 }]; +console.log('depth = default (1) : ', arr.flat()); +console.log('depth = 2 : ', arr.flat(2)); +console.log('depth = Infinity : ', arr.flat(Infinity)); +``` From 24d316461a6a66bab22ad693b07dc6c73fd87be7 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani <mamta.wardhani@gmail.com> Date: Wed, 18 Jun 2025 18:40:13 +0530 Subject: [PATCH 7/9] content fixes --- .../concepts/arrays/terms/flat/flat.md | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index aa253915859..d39ad78b392 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -1,33 +1,30 @@ --- Title: 'flat()' -Description: 'Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth' +Description: 'Creates a new array with all sub-array elements recursively concatenated into it up to the specified depth.' Subjects: - - 'Web Development' - 'Computer Science' + - 'Web Development' Tags: - 'Arrays' - 'Methods' - CatalogContent: - 'introduction-to-javascript' - 'paths/front-end-engineer-career-path' --- -The **`flat()`** method creates a new [array](https://www.codecademy.com/resources/docs/javascript/arrays) with all sub-array elements recursively concatenated up to the specified depth. It is a non-mutating method, meaning it returns a new array, leaving the original unchanged. +The **`flat()`** method creates a new [array](https://www.codecademy.com/resources/docs/javascript/arrays) with sub-array elements concatenated into it up to the specified depth. It is a non-mutating method, meaning it returns a new array without modifying the original one. ## Syntax -```js -array.flat(); -array.flat([depth]); +```pseudo +array.flat(depth); ``` -The **_optional_** `depth` parameter specifies how many levels of nested arrays to flatten. -If omitted, it defaults to `1`. +**Parameters:** -If set to `Infinity`, the method flattens all nested sub-arrays, regardless of their depth. +- `depth` (optional): The number of levels to flatten. Defaults to `1`. Use `Infinity` to flatten all nested arrays completely. -## Example 1: Default +## Example 1: Using `flat()` With Default Value This example demonstrates using `flat()` with the default depth of 1: @@ -44,7 +41,7 @@ The output of this code is: `arr.flat()` flattens one level deep, so the nested array `[3, 4]` is unpacked into the main array. -## Example 2: Default with nested sub-arrays +## Example 2: Using `flat()` on Deeper Nested Arrays This example demonstrates using `flat()` with the default depth of 1, with multiple layers of nested sub-arrays: @@ -61,7 +58,7 @@ The output of this code is: `arr.flat()` flattens the array one level deep. It unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. However, the inner array `[6, 7]` remains nested because it is at a deeper level. -## Example 3: Using a depth param +## Example 3: Using `flat()` with a Specified Depth This example demonstrates using `flat()` with a depth of 2, applied to an array with multiple layers of nested sub-arrays: @@ -73,12 +70,15 @@ console.log(arr.flat(2)); The output of this code is: ```shell -[1, 2, 3, 4, 5, 6, 7] +[ + 1, 2, 3, 4, + 5, 6, 7 +] ``` `arr.flat(2)` flattens the array two levels deep. First, it unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. Then, the inner array `[6, 7]` is unpacked, resulting in a fully flattened array with no nested sub-arrays. -## Example 4: Infinity +## Example 4: Using `flat()` with `Infinity` Depth This example demonstrates using `flat()` with a depth of `Infinity`, which fully flattens an array no matter how deeply nested its sub-arrays are: @@ -95,7 +95,7 @@ The output of this code is: `arr.flat(Infinity)` recursively flattens the array to its deepest level. All nested sub-arrays, no matter how deeply they are nested, are unpacked into a single flat array. This is useful when the depth of nesting is unknown or highly variable. -## Example 5: Sparse arrays +## Example 5: Using `flat()` on Sparse Arrays with Empty Slots This example demonstrates using `flat()` on sparse arrays: @@ -110,9 +110,9 @@ The output of the code is: [1, 2, 4, 6, 7] ``` -`flat()` removes the holes (empty slots) in the array whilst flattening. Even if the array is 1-level deep (no nested arrays) the sparse elements are still removed. +`flat()` removes empty slots (holes) in sparse arrays during flattening, treating them as if they don't exist. -## Example 6: Non-array elements +## Example 6: Flattening Arrays with Mixed Element Types The `flat()` method only flattens nested arrays. Elements that are not arrays remain the same: From dea8eab225c21b53c4f7fe0570a54e31f530336e Mon Sep 17 00:00:00 2001 From: Mamta Wardhani <mamta.wardhani@gmail.com> Date: Wed, 18 Jun 2025 18:41:26 +0530 Subject: [PATCH 8/9] Update flat.md --- content/javascript/concepts/arrays/terms/flat/flat.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index d39ad78b392..4d867b91185 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -24,6 +24,10 @@ array.flat(depth); - `depth` (optional): The number of levels to flatten. Defaults to `1`. Use `Infinity` to flatten all nested arrays completely. +**Return value:** + +A new array with the sub-array elements flattened up to the specified depth. The original array remains unchanged. + ## Example 1: Using `flat()` With Default Value This example demonstrates using `flat()` with the default depth of 1: From c7287879151fa259d507949a7a79cf4a81a6a2d9 Mon Sep 17 00:00:00 2001 From: Daksha Deep <dakshadeep1234@gmail.com> Date: Fri, 20 Jun 2025 21:35:27 +0530 Subject: [PATCH 9/9] minor changes --- content/javascript/concepts/arrays/terms/flat/flat.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/javascript/concepts/arrays/terms/flat/flat.md b/content/javascript/concepts/arrays/terms/flat/flat.md index 4d867b91185..9158ef2f8d7 100644 --- a/content/javascript/concepts/arrays/terms/flat/flat.md +++ b/content/javascript/concepts/arrays/terms/flat/flat.md @@ -30,7 +30,7 @@ A new array with the sub-array elements flattened up to the specified depth. The ## Example 1: Using `flat()` With Default Value -This example demonstrates using `flat()` with the default depth of 1: +This example demonstrates using `flat()` with the default depth of `1`: ```js const arr = [1, 2, [3, 4]]; @@ -47,7 +47,7 @@ The output of this code is: ## Example 2: Using `flat()` on Deeper Nested Arrays -This example demonstrates using `flat()` with the default depth of 1, with multiple layers of nested sub-arrays: +This example demonstrates using `flat()` with the default depth of `1`, with multiple layers of nested sub-arrays: ```js const arr = [1, 2, 3, [4, 5, [6, 7]]]; @@ -60,11 +60,11 @@ The output of this code is: [1, 2, 3, 4, 5, [6, 7]] ``` -`arr.flat()` flattens the array one level deep. It unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. However, the inner array `[6, 7]` remains nested because it is at a deeper level. +`arr.flat()` flattens the array one level deep. It unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. However, the inner array `[6, 7]` remains nested at a deeper level. ## Example 3: Using `flat()` with a Specified Depth -This example demonstrates using `flat()` with a depth of 2, applied to an array with multiple layers of nested sub-arrays: +This example demonstrates using `flat()` with a depth of `2`, applied to an array with multiple layers of nested sub-arrays: ```js const arr = [1, 2, 3, [4, 5, [6, 7]]]; @@ -80,7 +80,7 @@ The output of this code is: ] ``` -`arr.flat(2)` flattens the array two levels deep. First, it unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. Then, the inner array `[6, 7]` is unpacked, resulting in a fully flattened array with no nested sub-arrays. +`arr.flat(2)` flattens the array two levels deep. First, it unpacks the first-level nested array `[4, 5, [6, 7]]`, moving its elements into the main array. Then, the inner array `[6, 7]` is unpacked, resulting in an entirely flattened array with no nested sub-arrays. ## Example 4: Using `flat()` with `Infinity` Depth