0

The following command shows the properties of an Object.

var keys = Object.keys(result);

Output: [requester.client.id,request.id]

When I try to print an alert(result[request.id]) or alert(result.request.id) I dont get the values. Is there something I am missing?

6
  • have you tried alert(result['request.id']); Commented Jun 17, 2015 at 20:24
  • @NickAvi what? "request.id" as string? Commented Jun 17, 2015 at 20:25
  • @RokoC.Buljan Yes; as far as I can tell, the OP here appears to have properties named requester.client.id and request.id (i.e., the property names have period characters in them). Commented Jun 17, 2015 at 20:25
  • Instead of alert, try your browser's developer console. You can inspect objects, set breakpoints and perform other useful debugging operations. Commented Jun 17, 2015 at 20:25
  • @apsillers Yes, I got it now after a second look, anyway... seems to me that something is wrong down there... Commented Jun 17, 2015 at 20:27

2 Answers 2

2

In JavaScript objects keys are strings, though they can have periods. What you probably getting as the output is ['requester.client.id','request.id'], so it should be accessed as result['requester.client.id'].

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

Comments

0

Your result object has properties named "requester.client.id" and "request.id".

You need to do alert(result["request.id"]).

result[request.id] does not work because request here is treated as a variable name, and you probably have no variable named request.

result.request.id is closer, but it also fails because the property name has a period in it, so the parser treats this as the the id property of the request property of result.

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.