[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/toString [Back]  [Original]

Array.prototype.toString() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype.toString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Array toString() .

In this article

const array1 = [1, 2, "a", "1a"];

console.log(array1.toString());
// Expected output: "1,2,a,1a"

js
toString()

.

.

Array Object toString . toString join() . join , Object.prototype.toString [object Array] .

js
const arr = [];
arr.join = 1; // `join`  
console.log(arr.toString()); // [object Array]

console.log(Array.prototype.toString.call({ join: () => 1 })); // 1

, JavaScript toString .

Array.prototype.toString . Array.prototype.toString .

js
const matrix = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];

console.log(matrix.toString()); // 1,2,3,4,5,6,7,8,9

.

js
const arr = [];
arr.push(1, [3, arr, 4], 2);
console.log(arr.toString()); // 1,3,,4,2

toString()

js
const array1 = [1, 2, "a", "1a"];

console.log(array1.toString()); // "1,2,a,1a"

toString()

join() toString() undefined , .

js
console.log([1, , 3].toString()); // '1,,3'

toString()

toString() . this join() . , Object.prototype.toString() .

js
console.log(Array.prototype.toString.call({ join: () => 1 }));
// 1;  
console.log(Array.prototype.toString.call({ join: () => undefined }));
// undefined
console.log(Array.prototype.toString.call({ join: "not function" }));
// "[object Object]"

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.tostring


Web Proxy Viewer  |  New URL  |  Original Page