C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript TypedArray fill() methodThe JavaScript fill() method is used to fill all the elements of array from a start index to an end index with a static value. Syntax:array.fill(value) array.fill(value, start) array.fill (value start, end ) Parameters:Value(Required): The value to fill the array. Start(Optional): The index to start filling the array(default is 0). End(Optional): The index to stop filling the array (default is array.length). Return value:This function does not return a new array. Instead of, it transform the array on which this function is applied. Browser Support:
Example 1JavaScript TypedArray fill(value) method <script type="text/javascript"> // JavaScript to illustrate fill() method // Input array var arr1 = [1,2,3,4,5,6,7,8,9,10]; arr1.fill(20); document.write(arr1); // expected output: 20,20,20,20,20,20,20,20,20,20 </script> Output: 20,20,20,20,20,20,20,20,20,20 Example 2JavaScript TypedArray fill(value,start) method <script type="text/javascript"> // Input array // JavaScript to illustrate fill() method var arr1 = [1,2,3,4,5,6,7,8,9,10]; //value=20 , start index=2,fill arry with 20 arr1.fill(20,2); document.write(arr1); // expected output: 1,2,20,20,20,20,20,20,20,20 </script> Output: 1,2,20,20,20,20,20,20,20,20 Example 3JavaScript TypedArray fill(value,start,end) method <script type="text/javascript"> // JavaScript to illustrate fill() method // Input array var arr1 = [1,2,3,4,5,6,7,8,9,10]; //value=20 , start index=2, last index=3 //fill arry with 20 arr1.fill(20,2,3); document.write(arr1); // expected output: 1,2,20,4,5,6,7,8,9,10 </script> Output: 1,2,20,4,5,6,7,8,9,10
Next TopicJavaScript TypedArray Object
|