JavaScript Array valueOf() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Returns this

What You’ll Learn

The valueOf() method returns the array itself—the same object reference as this. It does not build a string or copy data. This tutorial explains why it exists, how it differs from toString(), and when (rarely) you might call it directly.

01

Syntax

valueOf()

02

Returns

Same array

03

Reference

arr === result

04

vs toString

Object vs string

05

Coercion

toString wins

06

ES3

Universal

Introduction

Every JavaScript object inherits valueOf() from Object.prototype. Arrays override it to return this—the array you called it on. So numbers.valueOf() gives you back numbers, not a flattened string like "1,2,3".

You will rarely call valueOf() directly in everyday code. It matters for understanding type coercion, the object model, and how arrays behave when JavaScript converts values.

Understanding the valueOf() Method

array.valueOf() returns the array object unchanged. Mutations through the returned reference affect the original array because they are the same object.

When an array is turned into a string (for example "Values: " + arr), JavaScript uses toString(), which produces comma-separated text. valueOf() is not the method that creates that string.

💡
Beginner Tip

Think of valueOf() as “give me the array object” and toString() as “give me a readable string of its elements.”

📝 Syntax

General form of Array.prototype.valueOf:

JavaScript
array.valueOf()

Parameters

  • None.

Return value

  • The same array object (this).

Common patterns

  • arr.valueOf() — returns arr (same reference).
  • arr === arr.valueOf() — always true.
  • String(arr) or arr.toString() — for display strings.
  • Number(arr) — uses different coercion rules (often NaN).

⚡ Quick Reference

QuestionAnswer
Return typeArray (object)
Same as original?arr === arr.valueOf()
String displayUse toString()
Compare two arraysNot with valueOf
Mutates array?No (but returns mutable ref)

📋 valueOf() vs toString() vs JSON.stringify()

valueOf returns the object; toString and JSON produce strings.

valueOf
array ref

Object

toString
comma str

Display

toLocaleString
locale str

i18n

JSON.stringify
JSON text

Data

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

valueOf returns the array object itself.

Example 1 — Returns the Same Array Reference

valueOf() does not copy or stringify.

JavaScript
const numbers = [1, 2, 3, 4, 5];

const result = numbers.valueOf();

console.log(result);
// [1, 2, 3, 4, 5]

console.log(numbers === result);
// true
Try It Yourself

How It Works

Strict equality confirms result and numbers are the same object in memory.

Example 2 — Changes Through valueOf() Affect the Original

The returned reference is live.

JavaScript
const items = ["a", "b"];

const ref = items.valueOf();
ref.push("c");

console.log(items);
// ["a", "b", "c"]
Try It Yourself

How It Works

ref and items are identical, so push on either updates both names for the same array.

📈 Practical Patterns

Contrast with toString and avoid equality traps.

Example 3 — valueOf() vs toString()

Different return types for the same array.

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

console.log(typeof nums.valueOf());
// "object"

console.log(typeof nums.toString());
// "string"

console.log(nums.toString());
// "10,20,30"
Try It Yourself

How It Works

valueOf keeps the array as an object. toString produces human-readable comma-separated text.

Example 4 — String Concatenation Uses toString()

Adding an array to a string does not print [object Array].

JavaScript
const numbers = [1, 2, 3];

const message = "Values: " + numbers.valueOf();

console.log(message);
// "Values: 1,2,3"
Try It Yourself

How It Works

valueOf() returns the array; the + operator then calls toString() on it for the string side of concatenation.

Example 5 — Do Not Compare Arrays with valueOf()

Identical contents, different objects—strict equality fails.

JavaScript
const a = [1, 2, 3];
const b = [1, 2, 3];

console.log(a.valueOf() === b.valueOf());
// false

console.log(JSON.stringify(a) === JSON.stringify(b));
// true (same contents)
Try It Yourself

How It Works

valueOf() returns each array object. === compares references, not element values.

🚀 Common Use Cases

  • Spec compliance — part of the object conversion protocol.
  • Learning coercion — understand ToPrimitive behavior.
  • Custom objects — contrast with Date, where valueOf returns a number.
  • Debugging identity — confirm you still hold the same array reference.
  • Legacy libraries — rare explicit calls in older codebases.
  • When not to use — string display, deep equality, or cloning.

🧠 How valueOf() Fits In

1

Call valueOf()

Array override runs.

Invoke
2

Return this

Same array object reference.

Object
3

Need a string?

Engine calls toString() instead.

Coerce
4

Comma text

Display via toString path.

📝 Notes

  • Returns the array object, not a primitive string or number.
  • arr === arr.valueOf() is always true.
  • Does not clone or copy elements.
  • String output comes from toString(), not valueOf().
  • Do not use for comparing array contents.
  • Dates override valueOf to return milliseconds—arrays do not.
  • ES3—universal browser support.

Browser & Runtime Support

Array.prototype.valueOf() has been available since ES3 as part of the core object model inherited from Object.prototype.

Baseline · ES3

Array.prototype.valueOf()

Supported in every browser and Node.js version—including very old environments. Behavior is identical everywhere.

100% Universal support
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.valueOf() Excellent

Bottom line: Safe everywhere. You will almost always use the array directly instead of calling valueOf explicitly.

Conclusion

valueOf() on arrays simply returns the array itself. For readable text, use toString() or join(). For data, use JSON.stringify(). Knowing valueOf() clarifies how JavaScript treats arrays during type conversion.

Next, learn with() to replace an element at an index without mutating the original array.

💡 Best Practices

✅ Do

  • Use the array variable directly (same as valueOf)
  • Use toString/join for display strings
  • Compare contents with deep equality or JSON
  • Learn valueOf for coercion fundamentals
  • Contrast with Date.valueOf (returns number)

❌ Don’t

  • Expect a comma string from valueOf directly
  • Check typeof valueOf() expecting "string"
  • Compare different arrays with valueOf ===
  • Call valueOf for cloning (use slice or spread)
  • Confuse valueOf with primitive unboxing

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.valueOf()

Returns the array object itself.

5
Core concepts
🔗 02

Same ref

arr === result.

Identity
📄 03

Object

Not a string.

Type
04

vs toString

Display path.

Compare
05

Equality

Ref not content.

Trap

❓ Frequently Asked Questions

valueOf() returns the array itself—the same object reference. For arrays, it does not convert elements to a string or number; it simply returns this.
No. valueOf() only returns a reference to the existing array. However, because it returns the same array, any changes you make through that reference affect the original.
Yes. arr === arr.valueOf() is true. They point to the same array object in memory.
valueOf() returns the array object. toString() returns a comma-separated string of elements. When JavaScript needs a string (e.g. in concatenation), it uses toString(), not the raw array from valueOf().
No. array1.valueOf() === array2.valueOf() compares references, so two separate arrays with identical contents still return false. Use a deep comparison or JSON.stringify for content equality.
Array.valueOf() has been available since ES3 and works in every browser and Node.js environment.
Did you know?

Wrapper objects like new Number(5) use valueOf() to unwrap to a primitive. Arrays are already objects, so their valueOf() just returns this rather than unboxing to a number or string.

Continue to with()

Learn how to replace an element at an index without mutating the original array.

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