TypeScript Array fill() Method Last Updated : 12 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The fill() method in TypeScript is utilized to replace all the elements within an array with a fixed value. This action alters the array itself and returns the updated version. This method is helpful for the easy transformation of an array in TypeScript.Syntaxarray.fill(value[, start[, end]])Parametersvalue: The value you want to use for populating the array.start (optional): The index from where you want to start filling the array (default is 0).end (optional): The index where you want to stop filling the array (default is the length of the array).Return ValueThe array that has been modified with the values. It is the array that was filled.Key Pointsfill() method does not alter the length of array, and only the content of array.It does not work on array with length=0, as there is no content in array.fill() method is not suitable to be used on strings, as strings are immutable.Examples of fill() in TypeScriptLet's see some more examples of array fill() method in TypeScript.Example 1: Filling a Portion of an Array with ZerosIn this example, we will fill a portion of an array with zeros. TypeScript let numbers: number[] = [1, 2, 3, 4, 5]; numbers.fill(0, 1, 4); console.log(numbers); Output:[1, 0, 0, 0, 5] Example 2: Filling a String Array with "Guest" from a Specific IndexIn this example, we will fill a string array with the value "Guest" starting from a specific index. TypeScript let guests: string[] = ['Pankaj', 'Rahul', 'Ankit']; guests.fill('Guest', 1); console.log(guests); Output:['Pankaj', 'Guest', 'Guest'] Comment More infoAdvertise with us Next Article TypeScript Array fill() Method P pankajbind Follow Improve Article Tags : JavaScript Web Technologies TypeScript Similar Reads PHP array_fill() function The array_fill() is an inbuilt-function in PHP and is used to fill an array with values. This function basically creates an user-defined array with a given pre-filled value. Syntax: array_fill($start_index, $number_elements, $values) Parameter: The array_fill() function takes three parameters and ar 2 min read JavaScript Array fill() Method The JavaScript Array fill() Method fills a given range of array elements with the given value. This method is used to manipulate the existing array according to our needs.Syntax:arr.fill(value,start,end)Parameters:Value: Value to be filled.Start: Start index (included) and its default value is 0.End 3 min read JavaScript Array fill() Method The fill() method in JavaScript is used to fill all the elements of an array from a start index to an end index with a static value. It mutates the original array and returns the modified array. Syntax: arr.fill(value, start, end)Parameters: This method accepts three parameters as described below: P 3 min read PHP array_fill_keys() Function The array_fill_keys() function is a builtin function in PHP and is used to create a new array filled with the given keys and value provided as an array to the function. Syntax: array array_fill_keys ( $keys, $value ) Parameters: This function accepts two parameters, keys and their values to be prese 3 min read 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 1 min read Like