2

excuse my ignorance if this is obvious or answered before . I have a string like this

var test = {"99":{"ttop":"0","lleft":"0","wwidth":"881","hheight":"78"},
"42":{"ttop":"91","lleft":"110","wwidth":"285","hheight":"26"},
"43":{"ttop":"91","lleft":"490","wwidth":"117","hheight":"26"},
"44":{"ttop":"91","lleft":"5","wwidth":"87","hheight":"26"},
"36":{"ttop":"91","lleft":"630","wwidth":"251","hheight":"26"}} 

I have read plenty about accessing with text identifiers (eg. "first-id" instead of "99") but I think my issue is that I get errors when I use a number for the id.

I Greatly appreciate your help

3 Answers 3

1

You need to use bracket notation instead of dot notation as member operator

test['99']
Sign up to request clarification or add additional context in comments.

1 Comment

You can leave off the quotes if you like, the name will get coerced to a string.
1

When the property name is not a valid identifier, use array syntax to access it:

test["99"]

Comments

0

You can also do it like that:

var biggestId = Object.keys(json).sort().pop();
console.log(test[biggestId]);

So you get value of biggest key in collection but it is data specific solution

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.