TypedArray fill() JavaScript

The Javascript TypedArray fill() method fills all the elements of an array from the start index to the end index with a static value.

Syntax:

array.fill(value)  
array.fill(value, start)  
array.fill (value, start, end)

Parameters: value: It represents the value to fill the array. start: It represents the index position to start filling the array. The default is 0. end: It represents the index position to end filling the array. The default is an array.length -1.

Returns: Size of the array without modification.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
Jewels.fill("GOLD");
document.write(Jewels);
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
const testArray = new Uint8Array([34, 45, 23, 10]);
testArray.fill(4, 1, 3);
document.write(testArray);
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com