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

flix
  • 1,688
  • 3
  • 34
  • 64

2 Answers2

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) 
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
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)
yajiv
  • 2,901
  • 2
  • 15
  • 25