JavaScript Array values() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Iterator

What You’ll Learn

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

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().

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.

📝 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.

⚡ Quick Reference

GoalCode
Iterator of valuesarr.values()
Loop valuesfor (const v of arr)
Index + value pairsarr.entries()
Indexes onlyarr.keys()
Copy to new array[...arr]
Mutates array?No

📋 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

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
Try It Yourself

How It Works

values() returns an iterator, not an array. Each loop iteration pulls the next value until done.

Example 2 — for...of on the Array (Equivalent)

Arrays default to the same values iterator.

JavaScript
const fruits = ["apple", "orange", "banana"];

for (const fruit of fruits) {
  console.log(fruit);
}
// apple
// orange
// banana
Try It Yourself

How It Works

arr[Symbol.iterator]() calls values() internally. Explicit values() is optional for simple loops.

📈 Practical Patterns

Copy, aggregate, and step manually.

Example 3 — Collect Values with Spread

Turn the iterator into a new array (shallow copy).

JavaScript
const nums = [10, 20, 30];

const copy = [...nums.values()];

console.log(copy);
// [10, 20, 30]

console.log(copy === nums);
// false
Try It Yourself

How It Works

Spread consumes the iterator into a new array. [...arr] is the common shorthand for the same copy.

Example 4 — Sum Numbers with values()

Aggregate while looping element values.

JavaScript
const scores = [88, 92, 76];

let total = 0;

for (const score of scores.values()) {
  total += score;
}

console.log(total);
// 256
Try It Yourself

How It Works

For totals, reduce() is often cleaner—but values() shows explicit iteration over elements only.

Example 5 — Manual next() Steps

Pull values one at a time from the iterator object.

JavaScript
const letters = ["a", "b", "c"];
const it = letters.values();

console.log(it.next());
// { value: "a", done: false }

console.log(it.next());
// { value: "b", done: false }

console.log(it.next().value);
// "c"
Try It Yourself

How It Works

Each next() returns { value, done }. When done: true, iteration is finished.

🚀 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.

📝 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.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · 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.

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.

💡 Best Practices

✅ Do

  • Use plain for...of when indexes are not needed
  • Use entries() when you need index + value
  • Spread or Array.from to collect iterator values
  • Create a fresh iterator to re-loop
  • Prefer reduce for simple aggregates

❌ Don’t

  • Expect an array back from values()
  • Reuse a consumed iterator without resetting
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.values()

Iterate element values with a lazy iterator.

5
Core concepts
🔄 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.

Continue to valueOf()

Learn how arrays return themselves from valueOf() during type conversion.

valueOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful