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.
To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.
To escape a single or double quote in a string, use a backslash \ character before each single or double quote in the contents of the string, e.g. 'that\'s it' . Copied!
Hi, Use Substr and Length function to remove first and last character from the string.
To remove double quotes in string. mahaveri. and the output should be formed without quotes such as serial number='s123343' ,to query a database. By using the CDATA convention you can refer to the quote character without messing up the compiler.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With