我正在尝试使用 document.write
编写嵌套数组,但它只写入 4
而不是 [[4]]
。这可能是什么原因?
document.write([[4]])
最佳答案
我相信这是因为 [[4]]
的字符串表示形式是 4
:
console.log([[4]].toString())
您可以使用document.write(JSON.stringify([[4]]))
做您想做的事:
console.log(JSON.stringify([[4]]))
或者,如果您需要更漂亮的格式:document.write('<pre>' + JSON.stringify([[4]],null,4) + '</pre>' )
document.write('<pre>' + JSON.stringify([[4]],null,4) + '</pre>' )
关于javascript - 为什么 document.write 不以数组格式写入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47950682/