Skip to main content
Chaint
Known Participant
Apr 28, 2023 7:24 AM UTC
Answered

A JavaScript error occurred. SyntaxError: missing } after property list

When I change the double quotes in the following code to single quotes, I get an error

before change

script = script.replace(/\"/g, "'");

after change

script = script.replace(/'/g, '\'');

How do I change to single quotes in the correct style

This topic is closed to new replies. Start a new post to keep the conversation going.
Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Apr 28, 2023 11:14 AM UTC

Hi,
What do you want to achieve with this regular expression?
If you want to replace all single quotes with double quotes, here's how:

script = script.replace(/'/g, '"')

 

 

 

- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation

3 replies

Multoman
Inspiring
Apr 28, 2023 11:31 AM UTC

I just want to add a little bit. If you want to change all the characters in a string, then instead of replace() you can use .split("").join("")

Example:

 

 

 

script = script.replace(/'/g, '"')
script = script.split("'").join('"') 

 

 

 

 

Translate
kglad
Community Expert
Community Expert
Apr 28, 2023 1:07 PM UTC

@Multoman 

 

that should be split("originalcharacter").join("replacementcharacter")

Translate
Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Apr 28, 2023 11:14 AM UTC

Hi,
What do you want to achieve with this regular expression?
If you want to replace all single quotes with double quotes, here's how:

script = script.replace(/'/g, '"')

 

 

 

Translate
- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation