JavaScript Array values()
Example
// Create an Array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// Create an Iterator
const list = fruits.values();
// List the Values
let text = "";
for (let x of list) {
text += x + "<br>";
}
Try it Yourself »
More Examples Below !
Description
The values()
method returns an Iterator object with the values of an array.
The values()
method does not change the original array.
Array Iteration Methods:
Syntax
array.values()
Parameters
NONE |
Return Value
Type | Description |
Iterator | An Iterator object containing the values of an array. |
More Examples
Example
Iterate directly over the Iterator:
// Create an Array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// List the Values
let text = "";
for (let x of values(fruits)) {
text += x + "<br>";
}
Try it Yourself »
Example
Use the built in Object.values() method:
// Create an Array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// List the Values
let text = "";
for (let x of Object.values(fruits)) {
text += x + "<br>";
}
Try it Yourself »
Array Tutorials:
Browser Support
values()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
values()
is not supported in Internet Explorer.