> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/array/fill.md).

# \_.fill（填充数组值）

**语法：**

```javascript
_.fill(array, value, [start=0], [end=array.length])
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L7202)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.fill)

**描述：**

从给定的开始位置填充给定的值，不包括结尾的位置的值。

> 注意：这个方法同时会引起原数组发生变化。

**开始版本：**&#x33;.2.0

**参数：**

* `array (Array):` 需要填充的数组. &#x20;
* `value (*):`　填充的值. &#x20;
* `[start=0] (number):` 开始的位置. &#x20;
* `[end=array.length] (number):` 结束位置.

**返回值：**

* `array (Array)`: 返回数组。

**例子：**

```javascript
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]
```
