javascript - What can I use instead of typeof in JS -
if have javascript array objects inside, this
articlesparams[itemid].properties.loaded if try this:
if ( typeof articlesparams[itemid].properties.loaded != 'undefined' && ...) { // something... } i have encountered problem if articleparams[itemid].properties undefined got error: cannot read property 'properties' of undefined.
so in case should stupid this:
if ( typeof articlesparams[itemid].properties != 'undefined' && typeof articlesparams[itemid].properties.loaded != 'undefined' && ...) { // something... } is equivalent in javascript in php isset() ?
an alternative this, quite typical in js:
if (articlesparams[itemid] && articlesparams[itemid].properties && articlesparams[itemid].properties.loaded && ...) { // something... } or this:
var item = articlesparams[itemid]; if (item && item.properties && item.properties.loaded && ...) { // something... } one point note not work if want if statement execute if loaded false. in case, better off checking if undefined using typeof.
Comments
Post a Comment