1

I have this JSON

{
"data":{
  "string-x": "21",
  "string-y": "110"
}
}

the string x and y is coordinates

I just want to call the coodinates by

data.string-x and data.string-y but I got this error

ReferenceError: x is not defined

what am I missing? it seems javascript treat data.string-x like equation not regular node call.

could anyone help me.

2
  • 5
    data['string-y'] ? Commented Feb 16, 2015 at 7:12
  • It's better to use camelCase stringX Commented Feb 16, 2015 at 7:29

1 Answer 1

4

data.string-x is treated as subtraction expression, equal to data.string - x

so change your code to data["string-x"]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.