json - Javascript: if an array has object or is no empty -


this question has answer here:

i have json data below:

{   "errorcode": null,   "message": "success",   "result": {    },   "totalrecord": 0,   "checkaccess": true,   "token": "fb8904acf4dbf0406ac3fd16acd9b84807d2a0e2913aecc3f39e90ca4b53161af6058ca5ee46b9877b75292e5ca9b8df969a325fa3b40c0e4acde546a431f55f6c07de8a854b9e0bf6aeba314d239267" }    

in json can find "result" empty, how can identify if statement? tried use !== "undedined" , !==null statment still executes.

if(trend1_data[0].result !== 'undefined'){     var resultone = trend1_data[0].result;     var chartval1 = resultone.mention30d.chartvalues;     for(var i=0; < chartval1.length; i++){         vol1.push(chartval1[i].value);//a loop generate value array         xvol1.push(chartval1[i].date);// xaris values e.g:date     } } 

result object inside json array

hope useful

var = [{ "errorcode": null,   "message": "success",   "result": {    },   "totalrecord": 0,   "checkaccess": true,   "token": "somevalue" }  ]  alert(object.keys(a[0].result).length) 

jsfiddle


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -