How to remove double quotes from array in JavaScript?
Suppose this is an array
enc= ["WPA2", "WPA2", "WPA2", "WPA2", "WPA1", "WEP", "WPA2", "WPA2", "WPA1", "WEP", "WEP"]
Thanks
Any help would be appreciated.
How to remove double quotes from array in JavaScript?
Suppose this is an array
enc= ["WPA2", "WPA2", "WPA2", "WPA2", "WPA1", "WEP", "WPA2", "WPA2", "WPA1", "WEP", "WEP"]
Thanks
Any help would be appreciated.
There are no double quotes in that array. The quotes just delimit the string literals, when they are parsed into strings they don't have quotes in them.
If you wanted to remove all the quotes from a string which actually had some in it:
str = str.replace(/"/g, ""); // RegEx to match `"` characters, with `g` for globally (instead of once)
You could do that in a loop over an array:
for (var i = 0; i < enc.length; i++) {
enc[i] = enc[i].replace(/"/g, "");
}
If you wanted to change the source code so that it looked like:
enc= [WPA2, WPA2, WPA2, WPA2, WPA1, WEP, WPA2, WPA2, WPA1, WEP, WEP]
… (and populated the array with some predefined variables) then you would be too late. The source code would have already been parsed by the JavaScript engine.
To get at variables when you have their names in strings, you would have to enter the murkey world of variable variables and are better off refactoring to use object properties (or going direct to an array).
This would be an error. Quotes are needed to mark the content beeing a string, not a variable.