I'm trying to get an array of all form objects within a large masterFormObject object. Is this the cleanest way to do so, or is there a better way I can check if the form objects themselves are not undefined directly and check both the applicant and account portion of this form object without having two separate blocks of undefined checks / forEach loops?vm.getAllForms = function (type) {  var allForms = [];  var accountForms = [];  var applicantForms = [];  if (undefined != vm.masterFormObject) {    if (undefined != vm.masterFormObject.payload) {      if (undefined != vm.masterFormObject.payload.accounts) {        vm.masterFormObject.payload.accounts.forEach(function (account) {          if (undefined != account.Forms) {            account.Forms.forEach(function (Form) {              allForms.push(Form);              accountForms.push(Form);            });          }        });      }      if (undefined != vm.masterFormObject.payload.accounts) {        vm.masterFormObject.payload.applicants.forEach(function (applicant) {          if (undefined != applicant.Forms) {            applicant.Forms.forEach(function (Form) {              allForms.push(Form);              applicantForms.push(Form);            });          }        });      }    }  }
Getting an array of certain objects within an object
javascript