I have an object called “message”
“message” holds an anonymous object (as a string):
{"action":"wakeup","hello":"testing123"}
// this is what I get when I output "message" with alert()
How do I address/get the content of “hello” from that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If
messageis a string (check it usingtypeof message === 'string'), you can create an object from it usingmessage = JSON.parse(message). After that you’ll havemessage.action(value ‘wakeup’) andmessage.hello(value ‘testing123’) available inmessage, now being an Object.If
messagealready is an Object,message.wakeupandmessage.helloshould both be available without conversion.