admin管理员组文章数量:1401361
In php I can do this to place a back slash inside an array
$symbols = array(".","\\\\");
What is the best method of doing this in javascript with backslash, colon, and semicolon?
In php I can do this to place a back slash inside an array
$symbols = array(".","\\\\");
What is the best method of doing this in javascript with backslash, colon, and semicolon?
Share Improve this question edited Jul 19, 2020 at 1:09 Unmitigated 89.8k12 gold badges99 silver badges104 bronze badges asked Jul 19, 2020 at 0:50 JonnyJonny 1,3291 gold badge15 silver badges27 bronze badges 2-
1
Inside a
string
value, correct? PHP and JavaScript share the same rules for backslash-escaped characters in strings which they inherited from C. – Dai Commented Jul 19, 2020 at 0:53 - yes inside of an array – Jonny Commented Jul 19, 2020 at 0:54
2 Answers
Reset to default 6Use an array literal delimited by square brackets:
var symbols = [".","\\", ":", ";"];
console.log(symbols);
See here for a more thorough explanation of arrays and their methods.
you need to scape backslash (backslash is the escape keyword). If you need to push an item to the array use the push() method.
let arr = ['\\', ':'];
arr.push(';');
console.log(arr); //Outputs ["\", ":", ";"]
本文标签: How can i place special characters in an array in javascriptStack Overflow
版权声明:本文标题:How can i place special characters in an array in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744267699a2598026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论