Open In App

JavaScript typedArray.fill() Method

The typedArray.fill() is an inbuilt function in JavaScript which is used to fill a value to typedArray from a start index to end index. 

Syntax:



typedarray.fill(value, start, end)

Parameters: It takes three parameters that are specified below-

Return value: It returns the modified array. JavaScript code to show the working of this function: 






// Creating some typedArrays
const A = new Uint8Array([ 0, 0, 0, 0 ]);
const B = new Uint8Array([ 0, 0, 0, 0 ]);
const C = new Uint8Array([ 0, 0, 0, 0 ]);
const D = new Uint8Array([ 0, 0, 0, 0 ]);
  
// Calling fill() function to fill different values
a = A.fill(4, 1, 3);
b = B.fill(5, 1);
c = C.fill(3);
d = D.fill(4, 0, 0);
  
// Printing modified array
console.log(a);
console.log(b);
console.log(c);
console.log(d);

Output:

0,4,4,0
0,5,5,5
3,3,3,3
0,0,0,0
Article Tags :