0

My JSON looks like this:

{Sean/Projet: 6, EC2: 1},{EC3:5,Weekend:5}

How do I dynamically access only the key, for example: "Sean/Projet" or "EC2".

Thank you.

5
  • Are you sure it doesn't look like [{Sean/Projet: 6, EC2: 1},{EC3:5,Weekend:5}]? Commented Mar 16, 2018 at 17:36
  • it looks like this {Sean/Projet: 6, EC2: 1} I think it is an object Commented Mar 16, 2018 at 17:37
  • That is a json object. And so is {EC3:5,Weekend:5}. The problem is the comma separating them, which implies an array. Commented Mar 16, 2018 at 17:39
  • Sorry for the mistake, the comma was introduced by me, I wanted to give 2 different examples not an array Commented Mar 16, 2018 at 17:41
  • Glad we cleared that up! Commented Mar 16, 2018 at 17:49

2 Answers 2

1

You can find that out by sorting the object by values.

var sortedKeys = keys.sort((a,b)=>{return b-a})

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

Comments

0

Found out a solution:

var keys = Object.keys(myJson);
console.log(keys[0]);

But how do I find out which key has the greater number?

1 Comment

You should ask a separate question for that

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.