Skip to content

Commit

Permalink
In flat() docs, change "ignore empty slots" to "remove empty slots"
Browse files Browse the repository at this point in the history
- I noticed that a later example uses the phrase "remove empty slots" in its language, otherwise I wouldn't have made this PR: 
- I think the "ignore" in "ignore empty slots" may be more technically correct, but "remove empty slots" paints a clearer picture and is harder to misinterpret. "Ignoring" an element could have meant it is returned without modification.
  • Loading branch information
DanKaplanSES authored Sep 29, 2024
1 parent 2089d21 commit d26ed52
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A new array with the sub-array elements concatenated into it.

The `flat()` method is a [copying method](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#copying_methods_and_mutating_methods). It does not alter `this` but instead returns a [shallow copy](/en-US/docs/Glossary/Shallow_copy) that contains the same elements as the ones from the original array.

The `flat()` method ignores empty slots if the array being flattened is [sparse](/en-US/docs/Web/JavaScript/Guide/Indexed_collections#sparse_arrays). For example, if `depth` is 1, both empty slots in the root array and in the first level of nested arrays are ignored, but empty slots in further nested arrays are preserved with the arrays themselves.
The `flat()` method removes empty slots if the array being flattened is [sparse](/en-US/docs/Web/JavaScript/Guide/Indexed_collections#sparse_arrays). For example, if `depth` is 1, both empty slots in the root array and in the first level of nested arrays are ignored, but empty slots in further nested arrays are preserved with the arrays themselves.

The `flat()` method is [generic](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#generic_array_methods). It only expects the `this` value to have a `length` property and integer-keyed properties. However, its elements must be arrays if they are to be flattened.

Expand Down

0 comments on commit d26ed52

Please sign in to comment.