2

I get the json from API, and the json look's like :

"diagnosis": {
  "type": [],
  "kode": [],
  "PrimaryCat": [],
  "Location": [],
  "Encountrace": [],
  "Fracture": [],
  "Healing": [],
}

Expected Result:

I want to store the keys into array, and the result should be

['type', 'kode', 'PrimaryCat', 'Location', 'Encountrace', 'Fracture', 'Healing']

it is possible to get it?

Refer to this question, I cant convert the code from android into javascript

1
  • 5
    var output = Object.keys(diagnosis) Commented Mar 21, 2018 at 8:32

2 Answers 2

3

Just use Object.keys method.

The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

const keys = Object.keys(diagnosis) 
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Object.keys. For more info see this

var diagnosis= {
  "type": [],
  "kode": [],
  "PrimaryCat": [],
  "Location": [],
  "Encountrace": [],
  "Fracture": [],
  "Healing": [],
}

var keys=Object.keys(diagnosis);
console.log(keys)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.