{"content":"Better than a thousand hollow words, is one word that brings peace."}
How to print the quote from above object without removing doubleqots
frm "content"
using javascript?
How to print the statement in the console
?
{"content":"Better than a thousand hollow words, is one word that brings peace."}
How to print the quote from above object without removing doubleqots
frm "content"
using javascript?
How to print the statement in the console
?
3
Answers
To access an object’s
content
property, there’s 2 notations in JavaScript:dot-notation
bracket-notation
For the bracket notation, the name of the property to be accessed can also be stored in a variable, which often occurs when looping over many objects with possibly unknown properties, and it is mandatory to use it whenever the name of the property is an invalid identifier. This is usually the case when the property name contains problematic characters, e.g. space(s), some non-alphanumeric characters and especially those ones that Javascript will interpret as an operator unless quoted (that is, part of a string).
The double quotes are not printed in the console unless the key is made up of multiple words. Even then, only single quotes is usually printed.
A workaround would be to do it manually:
Additionally, if you would like to extend this feature to all key-value pairs in the object, then you may write the following: