Keys of an object?


#1

I have an object for which the value of keys is dynamic
for example

obj ={ a: ‘v1’, b: ‘v2’, r : ‘g2’ }
on another day, the same object would have keys
obj ={ k: ‘v1’, l: ‘v2’, r : ‘g2’ }

how can I parse the objects if key values are not known beforehand ?


#2

Underscore has the function _.keys, which returns all of the object’s keys in strings.


#3

Thank, Worked perfect with _,keys using the underscore package


#4

Or you can use the vanilla function (no library needed):

Object.keys(yourObject)

which will give you the same result as underscore _.keys