Array.prototype.values()
Метод values()
повертає новий об'єкт ітератора масиву (Array Iterator
), який містить значення кожного елемента масиву.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
var a = ['a', 'б', 'в', 'г', 'ґ'];
var iterator = a.values();
console.log(iterator.next().value); // а
console.log(iterator.next().value); // б
console.log(iterator.next().value); // в
console.log(iterator.next().value); // г
console.log(iterator.next().value); // ґ
Синтаксис
arr.values()
Значення, що повертається
Новий об'єкт ітератора масиву.
Приклади
Перебір за допомогою циклу
for...of
var arr = ['а', 'б', 'в', 'г', 'ґ'];
var iterator = arr.values();
for (let letter of iterator) {
console.log(letter);
}
Array.prototype.values є реалізацією за замовчуванням для Array.prototype[Symbol.iterator].
Array.prototype.values === Array.prototype[Symbol.iterator] //true
TODO: please write about why we need it, use cases.
Специфікації
Специфікація | Статус | Коментар |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.values' in that specification. |
Standard | Початкове визначення. |
ECMAScript (ECMA-262) The definition of 'Array.prototype.values' in that specification. |
Living Standard |
Сумісність з веб-переглядачами
BCD tables only load in the browser