How to get all key in JSON object (javascript) -
{"document": {"people":[ {"name":["harry potter"],"age":["18"],"gender":["male"]}, {"name":["hermione granger"],"age":["18"],"gender":["female"]}, ]} }
from illustration json i want key keys in people such 'name', 'age', 'gender' has anyway it. thanks lot.
var input = {"document": {"people":[ {"name":["harry potter"],"age":["18"],"gender":["male"]}, {"name":["hermione granger"],"age":["18"],"gender":["female"]}, ]} } var keys = []; for(var = 0;i<input.document.people.length;i++) { object.keys(input.document.people[i]).foreach(function(key){ if(keys.indexof(key) == -1) { keys.push(key); } }); } console.log(keys);
javascript json
No comments:
Post a Comment