0

I have the following array (for exemple) :

[{id: 1, name: name1},
{id: 2, name: name2},
...]

I want to get (as a string) the labels of the array. So i want :

string1 = "id";
string2 = "name";

Is it possible ?

I guess another option would be to define string1 and string2 BEFORE initializing the array, and using string1 and string2 as label so I can use them separatly later, but that's not really what i'm looking for.

1 Answers1

0

Simply get the keys of first object in the array

Object.keys(obj[0])

This will give you an array ["id", "name"]

gurvinder372
  • 66,980
  • 10
  • 72
  • 94