JavaScript Array values() Method

JavaScript Array values() Method creates a new array iterator object that carries the values specified at each array index. 

The JavaScript Array values() method returns a new Array Iterator object that contains the values for each index in the array.

The values() method does not change the original array.

The values() method does not ignore empty array elements.



The values() method does not have any parameters.

Return value

Returns a new Array iterator object.


const array1 = ['a', 'b', 'c'];
const iterator = array1.values();

for (const value of iterator) {

// expected output: "a"
// expected output: "b"
// expected output: "c"
const languages = ["JavaScript", "Java", , "C++", "Python", "Lua"];
let iterator = languages.values();

// using .next() with iterator object
console.log(; // { value: 'JavaScript', done: false }

console.log(; // Java


for (let value of iterator) {

console.log( // { value: undefined, done: true }

If the next() method use exceeds the given array length, it will return an ‘undefined’ value.

<head> <h5> Javascript Array Methods </h5> </head>  
var arr=["John","Tom","Sheero","Romy","Tomy"]; //Initialized array  
var itr=arr.values();  
document.write("The array elements are: <br>");  
document.write("<br>"; //returns value at index 0.  
document.write("<br>"; //returns value at index 1  
document.write("<br>"; //returns value at index 2  
document.write("<br>"; //returns value at index 3  
document.write("<br>"; //returns value at index 4  
document.write("<br>"; //returns undefined  
It is clear that the size of the array was 4, i.e., arr[4]. But next() method was used for 5 times. Thus, the last call to next() had returned an ‘undefined’ value.

Iteration using for…of loop

const arr = ['a', 'b', 'c', 'd', 'e'];
const iterator = arr.values();

for (let letter of iterator) {
}  //"a" "b" "c" "d" "e"