How to expand a multidimensional array by javascript
This article mainly explains "javascript how to expand the multi-dimensional array", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "javascript how to expand the multi-dimensional array" bar!
Description
1. Flat () accepts an optional parameter, and the nested array specified by this parameter should be flattened.
If no parameter is provided, the default value is 1: if you enter the Infinity parameter, the array will flatten out no matter how many dimensions you have.
2. FlatMap () combines map () and flat () into a method. Create a new array with the return value of the supplied function, and then concatenate all subarray elements of the array.
The flat () method can flatten a multi-dimensional array into an one-dimensional array. If there are null values in the supplied array, they will be discarded.
Example
Let array_1 = [1,2,3, [4,5], 6]; let array_1_result = array_1.flat () Array_1_result / / [1, 2, 3, 4, 5, 6] Thank you for reading, the above is the content of "how to expand the multi-dimensional array of javascript". After the study of this article, I believe you have a deeper understanding of how to expand the multi-dimensional array of javascript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!