Sunday, June 14, 2026
HomeLanguagesJavascriptJavaScript typedArray.fill() Method

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-

  • value: It is the value to fill with typed array.
  • start: It is starting index, optional and its default value is 0.
  • end: It is ending index, optional and not included. Its default value is length of the typedArray.

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

javascript




// 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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS