简体   繁体   English

如何在 javascript 的数组中放置特殊字符

[英]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.

相关问题 如何解码JavaScript变量中的特殊字符? - How can I decode special characters in a JavaScript variable? 如何使用 javascript 删除 url 中的特殊字符? - how can i delete special characters in a url with javascript? 我如何将2个不同的特殊字符与jquery / javascript一样对待? - How can i treat 2 different special characters as the same with jquery/javascript? 如何删除嵌套数组中的特殊字符? - How can I delete special characters inside a nested array? 如何计算JavaScript数组中的字符? - How can I count characters in an JavaScript array? 使用JavaScript,如何在保留特定字符的情况下以一定长度将字符串断开? - Using JavaScript how can I break a string at a certain length, preserving special characters? 如何使用 javascript 制作密码生成器,我可以在其中切换长度、特殊字符、数字、大写和小写 - How to make a password generator with javascript where i can toggle length, special characters, numbers, uppercase and lowercase JavaScript、HTML:如何禁用 Shift 键(特别是与其他键组合以创建特殊字符时)? - JavaScript, HTML: How can I disable the Shift Key (specially when combined with other keys to create special characters)? 如何格式化包含特殊字符的javascript数组数据 - how to format javascript array data that contains special characters 如何将带有特殊字符的字符串修改为 javascript 中的对象数组 - how to modify string with special characters to array of objects in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM