The values() method returns an iterator over each element value in an array. This tutorial covers syntax, for...of loops, comparison with entries() and keys(), collecting values, and five practical examples.
01
Syntax
array.values()
02
Iterator
Lazy values
03
for...of
Loop elements
04
vs entries
Values only
05
Read-only
No mutation
06
ES2015
Wide support
Fundamentals
Introduction
Sometimes you need to walk every element without caring about its index. values() returns an iterator that yields each value in order—from index 0 to length - 1.
For plain arrays, looping with for...of already uses the same iterator under the hood. Calling values() explicitly is useful when an API expects an iterator or when you want symmetry with keys() and entries().
Concept
Understanding the values() Method
array.values() returns a new Array Iterator object. Each call to next() (or each step of for...of) produces the next element value.
The iterator does not copy the array. If the array changes while you iterate, later steps reflect those changes. The iterator itself does not mutate the array.
💡
Beginner Tip
Need indexes too? Use entries(). Need only indexes? Use keys(). Need only values? Use values() or plain for...of on the array.
Foundation
📝 Syntax
General form of Array.prototype.values:
JavaScript
array.values()
Parameters
None.
Return value
A new Array Iterator yielding element values.
Common patterns
for (const v of arr.values()) { ... }
for (const v of arr) { ... } — same for arrays.
[...arr.values()] — shallow copy as new array.
Array.from(arr.values()) — collect values.
const it = arr.values(); it.next().value; — manual step.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Iterator of values
arr.values()
Loop values
for (const v of arr)
Index + value pairs
arr.entries()
Indexes only
arr.keys()
Copy to new array
[...arr]
Mutates array?
No
Compare
📋 values() vs entries() vs keys() vs forEach()
All traverse arrays; iterators are lazy, forEach runs immediately.
values
element
Iterator
entries
[i, val]
Pairs
keys
index
Indexes
forEach
callback
Eager
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.
📚 Getting Started
Loop element values from the iterator.
Example 1 — Basic for...of with values()
Log each fruit from the iterator.
JavaScript
const fruits = ["apple", "orange", "banana"];
const iterator = fruits.values();
for (const fruit of iterator) {
console.log(fruit);
}
// apple
// orange
// banana
Each next() returns { value, done }. When done: true, iteration is finished.
Applications
🚀 Common Use Cases
Explicit iterators — APIs that accept iterable values.
Symmetry — alongside keys() and entries().
Lazy iteration — process one value at a time.
Shallow copy — [...arr.values()].
Teaching — understand iterator protocol.
When indexes matter — prefer entries() instead.
🧠 How values() Runs
1
Create iterator
New Array Iterator object.
Start
2
Track index
Internal cursor from 0 upward.
Cursor
3
Yield value
Return element at cursor.
next()
4
✅
done: true
After last index.
Important
📝 Notes
Returns an iterator, not an array.
Does not mutate the array.
for...of arr uses the same values iterator for arrays.
Sparse arrays yield undefined for empty slots.
Iterator is one-way; create a new one to restart.
ES2015—not available in IE.
For side-effect callbacks, forEach may be simpler.
Compatibility
Browser & Runtime Support
Array.prototype.values() was added in ES2015 (ES6) alongside keys() and entries() as part of the iterator protocol.
✓ Baseline · ES2015
Array.prototype.values()
Supported in Chrome 45+, Firefox 27+, Safari 9+, Edge (all versions), and Node.js 0.12+. Not supported in Internet Explorer.
97%Modern browsers
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.values()Excellent
Bottom line: Safe in all modern projects. Use a polyfill or for-loop only if you must support IE.
Wrap Up
Conclusion
values() exposes a lazy iterator over array elements. For everyday loops, for...of on the array is enough. Reach for values() when you need an explicit iterator or consistency with keys() and entries().
Next, learn valueOf() and how arrays behave during primitive conversion.
Modify array slots through iterator variables (primitives)
Use values() for deep equality checks (use proper compare)
Call values() in hot loops on IE without polyfill
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.values()
Iterate element values with a lazy iterator.
5
Core concepts
📝01
Syntax
values()
API
🔄02
Iterator
Lazy yield.
Protocol
📚03
for...of
Same for arrays.
Loop
📋04
vs entries
Values only.
Compare
🔒05
Read-only
No mutation.
Safe
❓ Frequently Asked Questions
values() returns a new Array Iterator. Each step yields the next element value from index 0 through length - 1, including undefined for empty slots in sparse arrays.
No. values() only creates an iterator over existing elements. Looping does not change the array.
For arrays, yes. Array.prototype[Symbol.iterator] returns the same iterator as values(), so for (const v of arr) behaves like for (const v of arr.values()).
values() yields each element only. entries() yields [index, value] pairs. Use values() when you do not need indexes.
forEach() runs a callback immediately and returns undefined. values() returns a lazy iterator you can loop, spread ([...arr.values()]), or pass to utilities.
values() is an ES2015 (ES6) feature. All modern browsers and Node.js support it; Internet Explorer does not.
Did you know?
Strings also have a values() method (ES2015) that yields each character. Array values() yields whole elements—one per index—not individual characters inside strings.