JavaScript | array.values()
The array.values() function is an inbuilt function in JavaScript which is used to returns 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 JavaScript program on array.values() function:
// Input array contain some elements var A = [ 'Ram', 'Z', 'k', 'geeksforgeeks' ]; // Here array.values() function is called. var iterator = A.values(); // All the elements of the array the array // is being printed. 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() function in JavaScript is used to print the elements of the given array.
Let’s see JavaScript program on array.values() function:
// Input array contain some elements. var array = [ 'a', 'gfg', 'c', 'n' ]; // Here array.values() function is called. var iterator = array.values(); // Here all the elements of the array is being printed. for (let elements of iterator) { console.log(elements); } |
Output:
> a, gfg, c, n
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
- this in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



