Skip to content

Commit

Permalink
update(JS): web/javascript/reference/global_objects/array/indexof
Browse files Browse the repository at this point in the history
  • Loading branch information
undead404 authored and AdriandeCita committed Oct 12, 2022
1 parent fbd810a commit 9bc7f7a
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ indexOf(searchElement, fromIndex)
Метод `indexOf()` пропускає порожні комірки в [розріджених масивах](/uk/docs/Web/JavaScript/Guide/Indexed_collections#rozridzheni-masyvy).

Метод `indexOf()` є [узагальненим](/uk/docs/Web/JavaScript/Reference/Global_Objects/Array#uzahalneni-metody-masyvu). Він лишень очікує, що значення `this` матиме властивість `length`, а також властивості з цілочисловими ключами.

## Приклади

### Використання indexOf()
Expand Down Expand Up @@ -108,6 +110,23 @@ updateVegetablesCollection(veggies, "шпинат");
console.log([1, , 3].indexOf(undefined)); // -1
```

### Виклик indexOf() на об'єктах-немасивах

Метод `indexOf()` зчитує з `this` властивість `length`, а потім звертається до кожної цілочислової властивості.

```js
const arrayLike = {
length: 3,
0: 2,
1: 3,
2: 4,
};
console.log(Array.prototype.indexOf.call(arrayLike, 2));
// 0
console.log(Array.prototype.indexOf.call(arrayLike, 5));
// -1
```

## Специфікації

{{Specifications}}
Expand Down

0 comments on commit 9bc7f7a

Please sign in to comment.