javascript - How to get the values of sub objects of json objects while using object.key method? -
by using api , getting response .in response, have got list of objects in deals named object , count of these object 19 .i have used below function 'keys' , 'values' of each object.but keys object has sub object contains keys , values ,i have tried m unable access them.i have given below snippet of response of api call.here i'm able access object @ index 0's active business got [object object] because has keys , values inside i.e 'id',that i'm unable access ,i want access them too.
meta: object response: object deals: array[20] 0: object active: 1 business: object id: 608290..... below function keys values of objects
function getallobjectdata(data) { $.each(data.response.deals, function (i, deals) { console.log("value of index " + i); var keys = [], values = []; $.each(deals, function (key, value) { keys.push(key); values.push(value); var subkey = [], subvalue = []; this part add , tried subobjects keys , values didnt work , dont know correct way.
$.each(key, function (subkey, subvalue) { <------------- alert(subkey + ": " + subkey); - }); - console.log('subkey ' + (i + 1) + ' ' + subkey); - console.log('subvalue ' + (i + 1) + ' ' + subvalue); - ----------------------------------------------------------------------------- }); console.log('keys ' + (i + 1) + ' ' + subkey); console.log('values ' + (i + 1) + ' ' + subvalue); }); }
i not sure need, if want access objects under deals array, can modify function below
function getallobjectdata(data) { $.each(data.response.deals, function (i, deal) { console.log("value of index " + i); var keys = [], values = []; // since looping through deals, no need create loop console.log(deal.active); //should output 1 console.log(deal.business.id); should output 608290 // , on... }
Comments
Post a Comment