Skip to content

Commit

Permalink
Example using Array.prototype.fill() on empty array (mdn#7429)
Browse files Browse the repository at this point in the history
* Added an example using the :scope pseudo class

* removed changes.md

* removed changes.md

* removed package-lock file

* adjusted to fit review suggestion

* remove file only to be used on local

* Added a note and example for using fill() with empty array

* Edited to adjust suggestions

* Merged mdn/main

Co-authored-by: Jean-Yves Perrier <[email protected]>
  • Loading branch information
Anurella and teoli2003 authored Sep 9, 2021
1 parent 108a735 commit b52e6a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ and use it to make a pull request.

1. Next, you'll want to start the local preview service, so you can see
the changes you'll make as they would look in production. Once started,
this local preview service is available at `http://localhost:5000`
this local preview service is available at `http://localhost:5000/`
within your browser.

```sh
Expand Down
1 change: 1 addition & 0 deletions files/en-us/web/api/element/queryselector/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h4 id="Javascript">JavaScript</h4>
</pre>

<h4 id="result">Result</h4>

<p>{{ EmbedLiveSample('Get_direct_descendants_using_the_scope_pseudo-class', 600, 160) }}</p>

<h3 id="The_entire_hierarchy_counts">The entire hierarchy counts</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ The modified array, filled with `value`.
- `fill` is a mutator method: it will change the array itself and return it, not a copy of it.
- If the first parameter is an object, each slot in the array will reference that object.

<div class="note notecard">
<b>Note</b>: Using Array.prototype.fill() on an empty array would not modify it as the array has nothing to be modified. To use Array.prototype.fill() when declaring an array, make sure to assign slots to the array.
<a href="#using_fill_to_populate_an_empty_array">See Example</a>
</div>

## Polyfill

```js
Expand Down Expand Up @@ -135,6 +140,15 @@ console.log(arr[1][0]); // 1
console.log(arr[2][0]); // 1
```

### Using fill() to populate an Empty Array

This example shows how to populate an array with random values. The end value
does not have to be specified.

```js
let tempGirls = Array(5).fill("girl",0);
```

## Specifications

{{Specifications}}
Expand Down

0 comments on commit b52e6a8

Please sign in to comment.