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 »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>";
}
More Examples Below !
Description
Thevalues() method returns an Iterator object with the values of an array.
Thevalues() 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 fruits.values()) {
text += x + "<br>";
}
Try it Yourself »const fruits = ["Banana", "Orange", "Apple", "Mango"];
// List the Values
let text = "";
for (let x of fruits.values()) {
text += x + "<br>";
}
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 »const fruits = ["Banana", "Orange", "Apple", "Mango"];
// List the Values
let text = "";
for (let x of Object.values(fruits)) {
text += x + "<br>";
}
Array Tutorials:
Browser Support
values() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers sinceJune 2017:
| Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |

