JS: Array.prototype.toString

By Xah Lee. Date: . Last updated: .

myArray.toString ()

Return a string representation of myArray.

For example, [3,4,5] becomes "3,4,5".

const arr = [3, 4, 5];
console.log (
    arr.toString () === "3,4,5"
); // true

// note: no bracket in result
console.log (
    [3, [1,[2]], 5].toString () === "3,1,2,5"
); // true

// note: no bracket in result, even for nested array
console.log (
    [3, {k:4}].toString () === "3,[object Object]"
); // true

[see JS: Array.prototype.join]

Reference

ECMAScript® 2016 Language Specification#sec-array.prototype.tostring

Array Topic

  1. JS: Array Basics
  2. JS: Understand JS Array
  3. JS: Create Array
  4. JS: Sparse Array
  5. JS: Array-Like Object
  6. JS: Array How-To

  1. JS: Array Object
  2. JS: Array.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth