📅  最后修改于: 2023-12-03 15:01:39.190000             🧑  作者: Mango
The array.values()
method is a built-in function in JavaScript that returns an iterable object containing the values of an array indexed from 0 to n-1. This method is supported by all modern browsers, including Internet Explorer 11 and Microsoft Edge.
array.values()
This method does not accept any parameters.
The array.values()
method returns a new Iterator
object that contains the values of each element in the array.
Here is an example of how the array.values()
method can be used:
const fruits = ['apple', 'banana', 'orange'];
const iterator = fruits.values();
for (const value of iterator) {
console.log(value);
}
/*
Output:
apple
banana
orange
*/
In this example, the array.values()
method is used to create an iterator object that contains the values of the fruits
array. The for...of
loop is used to iterate over the values in the iterator, and each value is logged to the console.
The array.values()
method is supported by all modern browsers, including Internet Explorer 11 and Microsoft Edge.
The array.values()
method in JavaScript returns an iterator object that contains the values of an array. This method is particularly useful for iterating over the values of an array in a concise and easy-to-read manner.