A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-fill-method/ below:

Lodash _.fill() Method - GeeksforGeeks

Lodash _.fill() Method

Last Updated : 30 Aug, 2024

Lodash _.fill() method is used to fill a set of values into the array in a given range.

Syntax:
_.fill(array, value, startIndex, endIndex);
Parameters:
Note:
Return Value:

Example 1: In this example, we are replacing the first four elements of the given array by 10 by the use of the lodash _.fill() method.

JavaScript
// Requiring the lodash library
let _ = require("lodash");

// Original array
let array = [2, 2, 3, 4, 5, 6]

// Printing original array 
console.log("Before : ", array)

// Using fill() method to replace
// values in range (0, 4]
_.fill(array, 10, 0, 4)

// Printing original array again 
console.log("After : ", array)

Output:

Example 2: In this example, we are replacing the first ten elements of the given array by 10 by the use of the lodash _.fill() method. and endIndex is greater than the size of array.

JavaScript
// Requiring the lodash library
let lodash = require("lodash");

// Original array
let array = [{ "aa": 1 },
{ "bb": 1 }, "a", "b"]

// Printing original array 
console.log("Before : ", array)

// Using fill() method to replace
// values in range (0, 10] greater
// then size of array
lodash.fill(array, 10, 0, 10)

// Printing original array again 
console.log("After : ", array)

Output:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4