Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the filling method of js array fill ()

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "js array fill () filling method is what", the article explains the content 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 "js array fill () filling method is what" it!

1. Fill () syntax

The fill () method populates all elements in an array from the start index to the end index with a fixed value. Terminating the index is not included. Returns the modified original array without creating a new array.

Use syntax: array.fill (value [, start [, end]]), where:

The value used by value to populate the array elements, required.

Start has an optional starting index, with a default value of 0.

End optionally terminates the index, and the default value is this.length.

2. Use of fill () / / when a single parameter is passed in, the method populates the entire array var arr1 = new Array (5) console.log (arr1.fill (1)) with the value of that parameter; / / [1 var arr2 = [1,2,3,4] console.log (arr2.fill (0)) / / when two parameters are passed, the first parameter is the filled element, and the second is the starting position of the filled element var arr3 = [0,1,2,3,4,5,6] console.log (arr3.fill (1,3)) / / when three parameters are passed in, the first parameter is the filled element, the second parameter and the third parameter refer to the start and end positions of the filled element, respectively, and the stop position element var arr4 = [0force1jue 2,3,4,5] console.log (arr4.fill (1,3,5)) is not modified. / / if the starting position or ending position provided is negative, the length of the array will be added to calculate the final position. For example, if the starting position is-1, it is equivalent to array.length-1 var arr5 = [0Magol 2,3,4,5] console.log (arr5.fill (1,-3)). / / [0Jing 1Jing 2jue 1JI] var arr6 = [0Jing 1Jing 2,3,4,5] console.log (arr6.fill (1, 3,-2)) Thank you for your reading. The above is the content of "what is the filling method of js array fill ()". After the study of this article, I believe you have a more profound understanding of what the filling method of js array fill () is, 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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report