Using a doublequote as a value in a JavaScript object

Albert F Gordon 21 Reputation points
2022-08-26T03:36:29.087+00:00

I've written a small script to decode morse code strings into regular character strings. To achieve this, I use an object that contains "name:value" pairs which are matched when iterating through the encoded string.

".-..-." is morse code for double quotes. My script works, but when I include the following "name:value" for double quotes, the output is wrong:

var mc_obj {  
...  
name:value pairs  
...  
".-..-.":'"' //<-- How do I correctly enter this value for double quote?  
};  
Microsoft 365 and Office Development Office JavaScript API
0 comments No comments
{count} votes

Accepted answer
  1. Dillon Silzer 57,826 Reputation points Volunteer Moderator
    2022-08-26T04:57:10.677+00:00

    Hi @AlbertFGordon-1419

    You can escape double quotes with a forward slash

    Example: \"

    "Then he said, \"Hello, World!\""; will print Then he said, "Hello, World!"


    If this is helpful please accept answer.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sam of Simple Samples 5,546 Reputation points
    2022-08-26T05:23:54.323+00:00

    JavaScript makes it easier than most languages. If I understand the question then you can just use:

    '.-..-.:"'  
    

    Very simple. You probably expected it to be more complicated. I see you know you can use a single quote but it is just easier than you expected.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.