TypeScript Array fill() Method Last Updated : 12 Jul, 2024 Summarize Comments Improve Suggest changes Share 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 JavaScript typedArray.fill() Method P pankajbind Follow Improve Article Tags : TypeScript Similar Reads Arrays.fill() in Java with Examples The Arrays.fill() is a method in the java.util.Arrays class. This method assigns a specified value to each element of an entire array or a specified range within the specified array.Example:Now let's understand this with the below simple example to fill an entire array with a specified value:Javaimp 3 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 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 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 How to Fill (initialize at once) an Array in Java? An array is a group of like-typed variables that are referred to by a common name. In this, article we will learn about Filling array in Java while Initialization.Example:Java// Java program to fill the element in an array import java.util.*; public class Geeks { public static void main(String args[ 3 min read Like