| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/toString | [Back] [Original] |
Get to know MDN better
const array1 = [1, 2, "a", "1a"];
console.log(array1.toString());
// Expected output: "1,2,a,1a"
toString()
Array Object toString toString join() join Object.prototype.toString [object Array]
const arr = [];
arr.join = 1; // `join`
console.log(arr.toString()); // [object Array]
console.log(Array.prototype.toString.call({ join: () => 1 })); // 1
JavaScript toString()
const array1 = [1, 2, "a", "1a"];
console.log(array1.toString()); // "1,2,a,1a"
join() toString() undefined
console.log([1, , 3].toString()); // '1,,3'
toString() this join() Object.prototype.toString()
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]"
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.tostring |
ArrayArray.prototype.at()Array.prototype.concat()Array.prototype.copyWithin()Array.prototype.entries()Array.prototype.every()Array.prototype.fill()Array.prototype.filter()Array.prototype.find()Array.prototype.findIndex()findLast()Array.prototype.findLastIndex()Array.prototype.flat()Array.prototype.flatMap()Array.prototype.forEach()Array.prototype.includes()Array.prototype.indexOf()Array.prototype.join()Array.prototype.keys()Array.prototype.lastIndexOf()Array.prototype.map()Array.prototype.pop()Array.prototype.push()Array.prototype.reduce()Array.prototype.reduceRight()Array.prototype.reverse()Array.prototype.shift()Array.prototype.slice()Array.prototype.some()Array.prototype.sort()Array.prototype.splice()Array.prototype.toLocaleString()Array.prototype.toReversed()Array.prototype.toSorted()Array.prototype.toSpliced()Array.prototype.toString()Array.prototype.unshift()Array.prototype.values()Array.prototype.with()Array.prototype[Symbol.iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()| Web Proxy Viewer | New URL | Original Page |