[英]How can i place special characters in an array in javascript
In php I can do this to place a back slash inside an array在 php 我可以这样做在数组中放置一个反斜杠
$symbols = array(".","\\\\");
What is the best method of doing this in javascript with backslash, colon, and semicolon?在 javascript 中使用反斜杠、冒号和分号执行此操作的最佳方法是什么?
Use an array literal delimited by square brackets:使用由方括号分隔的数组字面量:
var symbols = [".","\\", ":", ";"]; console.log(symbols);
See here for a more thorough explanation of arrays and their methods.有关 arrays 及其方法的更详尽说明,请参见此处。
you need to scape backslash (backslash is the escape keyword).您需要转义反斜杠(反斜杠是转义关键字)。 If you need to push an item to the array use the push() method.如果您需要将项目推送到数组,请使用 push() 方法。
let arr = ['\\', ':']; arr.push(';'); console.log(arr); //Outputs ["\", ":", ";"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.