Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove double quotes in javascript? [closed]

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.

like image 737
Mohd Anas Avatar asked May 31 '13 13:05

Mohd Anas


People also ask

How do you remove double quotes?

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.

How do you escape a double quote in JavaScript?

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!

How do I remove the first and last quotes from a string?

Hi, Use Substr and Length function to remove first and last character from the string.

How do you remove double quotes in mule 4?

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.


1 Answers

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).

like image 98
Quentin Avatar answered Nov 02 '22 14:11

Quentin