[英]How to convert a 2d array to a 2d string in javascript
The problem is quite simple.问题很简单。 I would like to convert a 2d array to a string and preserve the brackets.我想将二维数组转换为字符串并保留括号。 How can I do that?我怎样才能做到这一点? The String() method will remove all the brackets, unfortunately.不幸的是,String() 方法将删除所有括号。
Example: [[21, 21], [19, -2]]
should be converted to "[[21, 21], [19, -2]]"
示例: [[21, 21], [19, -2]]
应转换为"[[21, 21], [19, -2]]"
Do I need to build a for-loop to do that or is there built-in method or something similar I can use?我是否需要构建一个 for 循环来做到这一点,或者是否有内置方法或我可以使用的类似方法?
Thank you谢谢
Try尝试
let a = [[21, 21], [19, -2]]; console.log( JSON.stringify(a) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.