The Javascript array.values() is an inbuilt method in JavaScript that is used to return a new array Iterator object that contains the values for each index in the array i.e, it prints all the elements of the array.
Syntax:
arr.values()
Return values: It returns a new array iterator object i.e, elements of the given array.
Examples:
Input:
A = ['a', 'b', 'c', 'd']
Output:
a, b, c, d
Here as we see that input array contain some
elements and in output same elements get printed.
Let’s see the JavaScript program on the array.values() function:
Example: In this example, we will print the values of an array using the array values() method.
JavaScript
let A = [ 'Ram' , 'Z' , 'k' , 'geeksforgeeks' ];
let iterator = A.values();
console.log(iterator.next().value);
console.log(iterator.next().value);
console.log(iterator.next().value);
console.log(iterator.next().value);
|
Output:
Ram
z
k
geeksforgeeks
Application: This array.values() method in JavaScript is used to print the elements of the given array.
Let’s see the JavaScript program on the array.values() method:
Example: In this example, we will be using the array values() method with for loop to print the values of an array.
JavaScript
let array = [ 'a' , 'gfg' , 'c' , 'n' ];
let iterator = array.values();
for (let elements of iterator) {
console.log(elements);
}
|
Output:
a
gfg
c
n
We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
Supported Browser:
- Google Chrome 66 and above
- Microsoft Edge 12 and above
- Firefox 60 and above
- Opera 53 and above
- Safari 9 and above
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
18 May, 2023
Like Article
Save Article