JavaScript 获取嵌套数组(1 级),引号用 console.log 保留数字

JavaScript Get nested array (1 level) with quotes preserving numbers with console.log

我怎样才能采取

形式的东西

[["[]",2,"c"],["d","e","f"]]

并记录

[["[]","2","c"],["d","e","f"]]

到控制台? 我试过 console.log(array.toString()) 但那只是日志

[[[],2,c],[d,e,f]]

您可以使用 JSON.stringify 并记录

console.log(JSON.stringify([["[]",2,"c"],["d","e","f"]]))

如果你想保留双引号 " 那么你可以使用

console.log(${'[["[]",2,"c"],["d","e","f"]]'})

否则你可以使用

console.log(JSON.stringify([["[]",2,"c"],["d","e","f"]]))

这将保留数组并仅将内部数组项转换为字符串。

var data = [["[]",2,"c"],["d","e","f"]];
var stringed = data.map((d)=>{
  return (d.toString().split(","))
});
console.log(stringed);