Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove quotes in javascript

I am getting data in a variable as ""Value"". So, I want to remove quotes but only inner quotes. I tried with this but it's not working.

var value = "fetchedValue";
value = value.replace(/\"/g, "");

Can anyone explain with an example?

expected = "Value"
like image 548
Vishesh Avatar asked Mar 24 '18 09:03

Vishesh


People also ask

How do I remove a single quote from a string?

Therefore, to remove single quote from string column, we can use gsub function by defining the single quote and replacing it with blank(not space) as shown in the below examples.

How do you replace a quote in JavaScript?

Use the String. replace() method to replace single with double quotes, e.g. const replaced = str. replace(/'/g, " ); . The replace method will return a new string where all occurrences of single quotes are replaced with double quotes.

How do you remove single quotes and double quotes from a string in Java?

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.


1 Answers

It's weird. Your solution should work.
Well, try this:

var value = "fetchedValue";
value = value.slice(1, -1);
like image 172
Sagar Chaudhary Avatar answered Oct 05 '22 04:10

Sagar Chaudhary