Rajesh Rajesh - 8 months ago 26
jQuery Question

how to get field names from array of fields

My object like this

var obja = [{USER:"bob", SCORE:2000, TIME:32, AGE:16, COUNTRY:"US"},`{USER:"jane", SCORE:4000, TIME:35, AGE:16, COUNTRY:"DE"},`{USER:"tim", SCORE:1000, TIME:30, AGE:17, COUNTRY:"UK"},` {USER:"mary", SCORE:1500, TIME:31, AGE:19, COUNTRY:"PL"}];

but i want to store only fields USER,SCORE,TIME,AGE,COUNTRY in to array

Kld Kld

You can get an object keys this way

var obja = [{USER:"bob",  SCORE:2000, TIME:32,    AGE:16, COUNTRY:"US"}, {USER:"jane", SCORE:4000, TIME:35,    AGE:16, COUNTRY:"DE"},{USER:"tim",  SCORE:1000, TIME:30,    AGE:17, COUNTRY:"UK"}, {USER:"mary", SCORE:1500, TIME:31,    AGE:19, COUNTRY:"PL"}];

for(var key  in obja[0]){