add after ary assign assignIn assignInWith assignWith at before bind bindAll bindKey camelCase capitalize castArray ceil chain chunk clamp clone cloneDeep cloneDeepWith cloneWith compact concat conformsTo countBy create curry curryRight debounce deburr defaults defaultsDeep defer delay difference divide drop dropRight each eachRight endsWith entries entriesIn eq escape every extend extendWith fill filter find findIndex findKey findLast findLastIndex findLastKey first flatMap flatMapDeep flatMapDepth flatten flattenDeep flattenDepth flip floor forEach forEachRight forIn forInRight forOwn forOwnRight fromPairs functions functionsIn get groupBy gt gte has hasIn head inRange includes indexOf initial intersection invert invertBy invoke invokeMap isArguments isArray isArrayBuffer isArrayLike isArrayLikeObject isBoolean isBuffer isDate isElement isEmpty isEqual isEqualWith isError isFinite isFunction isInteger isLength isMap isMatch isMatchWith isNaN isNative isNil isNull isNumber isObject isObjectLike isPlainObject isRegExp isSafeInteger isSet isString isSymbol isTypedArray isUndefined isWeakMap isWeakSet join kebabCase keyBy keys keysIn last lastIndexOf lowerCase lowerFirst lt lte map mapKeys mapValues max maxBy mean meanBy memoize merge mergeWith min minBy multiply negate nth omit omitBy once orderBy overArgs pad padEnd padStart parseInt partial partialRight partition pick pickBy pull pullAll pullAllBy pullAllWith pullAt random rearg reduce reduceRight reject remove repeat replace rest result reverse round sample sampleSize set setWith shuffle size slice snakeCase some sortBy sortedIndex sortedIndexOf sortedLastIndex sortedLastIndexOf sortedUniq split spread startCase startsWith subtract sum sumBy tail take takeRight tap template throttle thru toArray toFinite toInteger toLength toLower toNumber toPairs toPairsIn toPlainObject toSafeInteger toString toUpper transform trim trimEnd trimStart truncate unary unescape union uniq uniqBy uniqWith unset unzip unzipWith update updateWith upperCase upperFirst values valuesIn without words wrap wrapperAt wrapperChain wrapperCommit wrapperFlatMap wrapperLodash wrapperNext wrapperPlant wrapperReverse wrapperToIterator wrapperValue xor zip zipObject zipObjectDeep zipWith

Lodash _.fill


The _.fill() method in lodash is a utility function that can be used to fill an array with a certain value. This method takes three parameters:

  1. array: The array to fill.
  2. value: The value to fill the array with.
  3. start (optional): The index to start filling the array from. If this value is not provided, the array will be filled starting at index 0.

Here is an example of using the _.fill() method to fill an array with the value 'apple' from index 1 to 3:

const arr = ['banana', 'orange', 'grape', 'kiwi'];
_.fill(arr, 'apple', 1, 3);

// Output: ['banana', 'apple', 'apple', 'kiwi']

In this example, the _.fill() method is called with the arr array as the first parameter, 'apple' as the second parameter, and 1 and 3 as the third and fourth parameters, respectively. This causes the arr array to be filled with 'apple' from index 1 to 3, resulting in the output ['banana', 'apple', 'apple', 'kiwi'].

If the start parameter is not provided, the _.fill() method will fill the entire array with the specified value:

const arr = ['banana', 'orange', 'grape', 'kiwi'];
_.fill(arr, 'apple');

// Output: ['apple', 'apple', 'apple', 'apple']

In this example, the _.fill() method is called with the arr array as the first parameter and 'apple' as the second parameter. Since the start parameter is not provided, _.fill() fills the entire arr array with 'apple', resulting in the output ['apple', 'apple', 'apple', 'apple'].

The _.fill() method is useful when you need to initialize an array with a certain value, or when you need to reset a portion of an array to a certain value. It can be used in a wide variety of scenarios, such as filling an array with zeroes or resetting a portion of an array to a default value.