Function fill

  • Fills elements of array with value from start up to, but not including, end.

    Note: This method mutates array.

    Type Parameters

    • T

    Parameters

    • array: any[]

      The array to fill.

    • Optionalvalue: T

      The value to fill array with.

    Returns T[]

    Returns array.

    5.10.0

    var array = [1, 2, 3];

    fill(array, 'a');
    console.log(array);
    // => ['a', 'a', 'a']

    fill(Array(3), 2);
    // => [2, 2, 2]

    fill([4, 6, 8, 10], '*', 1, 3);
    // => [4, '*', '*', 10]
  • Fills elements of array with value from start up to, but not including, end.

    Note: This method mutates array.

    Parameters

    • array: any[]

      The array to fill.

    • Optionalvalue: any

      The value to fill array with.

    • Optionalstart: number

      The start position.

    • Optionalend: number

      The end position.

    Returns any[]

    Returns array.

    5.10.0

    var array = [1, 2, 3];

    fill(array, 'a');
    console.log(array);
    // => ['a', 'a', 'a']

    fill(Array(3), 2);
    // => [2, 2, 2]

    fill([4, 6, 8, 10], '*', 1, 3);
    // => [4, '*', '*', 10]