Reputation: 1329
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?
Upvotes: 2
Views: 5850
Reputation: 89414
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.
Upvotes: 6
Reputation: 4572
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 ["\", ":", ";"]
Upvotes: 1