简体   繁体   English

从数组转换为字符串后,字符串不能去掉引号

[英]Can't get a string rid of quotes after being converted from array to string

I have this code:我有这个代码:

 users = [{ "userid": "45", "name": "steve" }, { "userid": "32", "name": "john" }]; getuser = users.flatMap(user => user.userid === '32'? user.name: []); result = getuser.toString(); console.log(result.replaceAll("\"", ""))

fiddle here: https://jsfiddle.net/Ldob8vz2/3/在这里小提琴: https://jsfiddle.net/Ldob8vz2/3/

this should output simple john without the quotes but no matter what I do, I can't get rid of those quotes.这应该 output 没有引号的简单john ,但无论我做什么,我都无法摆脱这些引号。 Why is that?这是为什么?

The quotes are an artifact of the way JSFiddle's console displays string values.引号是 JSFiddle 的控制台显示字符串值的方式的产物。 If you open the browser's native console, you can see that console does not print the quote marks.如果您打开浏览器的本机控制台,您可以看到该控制台不打印引号。

Also, the console implementation used by Stack Snippets also does not include the quote marks, as demonstrated here (your code without the replace):此外,Stack Snippets 使用的console实现也不包括引号,如此处所示(您的代码没有替换):

 users = [{ "userid": "45", "name": "steve" }, { "userid": "32", "name": "john" }]; getuser = users.flatMap(user => user.userid === '32'? user.name: []); result = getuser.toString(); console.log(result)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM