babbleon Posted July 11, 2018 Share Posted July 11, 2018 Hello, If i want to check if a mesh has some metadata, I have to check first if it has metadata, then thing specific metadata... eg: if (evt.pickInfo.pickedMesh.metadata) { if (evt.pickInfo.pickedMesh.metadata.pointType === 'source') { console.log('mesh as metadata: source'); } } Can this be condensed into just one if line? Thank you, Quote Link to comment Share on other sites More sharing options...
Arte Posted July 11, 2018 Share Posted July 11, 2018 @babbleon You can implement like: let hasOwnNestedProperty = function(obj, path) { for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) { obj = obj[path[i]]; if (!obj) return false; } return true; }; if ( hasOwnNestedProperty(evt.pickInfo.pickedMesh,'metadata.pointType') && evt.pickInfo.pickedMesh.metadata.pointType === 'source' ) { console.log('mesh as metadata: source'); } } Nabroski 1 Quote Link to comment Share on other sites More sharing options...
babbleon Posted July 11, 2018 Author Share Posted July 11, 2018 Thank you @Arte Arte 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.