JavaScript Array valueOf() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.valueOf() returns the same array object (this). It does not copy elements or build a string. Inherited from Object.prototype (ES3)—rarely needed in day-to-day code.

Remember
array.valueOf()  →  the same array (same reference)

arr === arr.valueOf()     → true
valueOf()  → object (the array)
toString() → "a,b,c" string

shared reference → mutations affect the original
not for deep equality of two arrays

Syntax

Call array.valueOf. Start with this line.

JavaScript
array.valueOf()
CallWhat it does
array.valueOf()Primary signature.
array.valueOf(...)Call with the arguments your case needs.

Built into JavaScript. Call valueOf(...) on an array instance — no import required.

Library declarations
JavaScript
array.valueOf()

Parameters

ParameterDescription
Receiver arrayRequired. Object whose reference is returned

Return Value

Return ValueDescription
*The same array (this)

JavaScript Examples

Example 1 — Same Array Reference

Prove valueOf() returns the identical object—not a clone.

JavaScript
const numbers = [1, 2, 3, 4, 5];
const result = numbers.valueOf();

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

How It Works

  1. Create an array. numbers points to one object.
  2. Call valueOf. Returns that same object into result.
  3. Contents look identical. Logging shows the same elements.
  4. === is true. Reference equality confirms there was no copy.

Example 2 — Shared Reference Mutations

Changing the return value changes the original array.

JavaScript
const items = ["a", "b"];
const ref = items.valueOf();

ref.push("c");

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

How It Works

  1. Alias the array. ref is another name for items.
  2. Mutate via ref. push("c") grows that one object.
  3. Original updates. items shows the new element too.
  4. Need a copy? Use slice() or [...items], not valueOf().

Example 3 — valueOf() vs toString()

Different jobs: object reference vs comma-separated string.

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

  1. valueOf stays an object. typeof reports "object" (arrays are objects).
  2. toString builds text. Elements joined with commas.
  3. String contexts use text. e.g. "" + nums ends up like toString().
  4. Pick by goal. Need text → toString/join; need the array → just use nums.

Browser & Runtime Support

Array.prototype.valueOf() has been part of JavaScript since ES3. It is available in every browser and Node.js environment you are likely to meet.

✓ Baseline · ES3

Array.prototype.valueOf()

Supported in all modern browsers, Internet Explorer, and every Node.js version. No polyfill required.

100% Browser 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() Universal

Bottom line: Safe everywhere. This is one of the oldest array/object methods in the language.

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 typically ends up using toString() because valueOf() did not produce a primitive.
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.

Next: with()

Return a new array with one index replaced—without mutating the original.

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.

11 people found this page helpful