underscore.js - How to get these key in JavaScript object -
i have next object:
var input = { "document": { "people":[ {"name":"harry potter","age":"18","gender":"male"}, {"name":"hermione granger","age":"18","gender":"female"} ] } }
i :
_.each(result.document[people], function(item){ console.log(item); //what should here ? or come wrong way ? });
and in item :
{name : 'harry potter', age : '18':, gender:'male'} {name : 'hermione grange', age : '18':, gender:'female'}
i [name,age,gender]. should do?
if think values dynamic utilize function first
var input = { "document": { "people":[ {"name":"harry potter","age":"18","gender":"male"}, {"name":"hermione granger","age":"18","gender":"female"} ] } } var func = function (one, two) { var array = input[one][two]; var arr =[]; (var i=0; i<array.length; i++){ arr = object.keys(array[0]); } homecoming arr; } func("document", "people"); // homecoming ["name", "age", "gender"]
javascript underscore.js lodash
No comments:
Post a Comment