I`m trying to parse a parsed xml2js response to json response in backend.  if (resp['soapenv:Envelope'] && resp['soapenv:Envelope']['soapenv:Body'] &&        resp['soapenv:Envelope']['soapenv:Body'][0] &&        resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'] &&        resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0]) {        var result =        resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0];        if (result.sevReturn &&            result.sevReturn[0]) {            var sev =                result['sevReturn'][0]['Sev'];            if (sev) {// Build json}            }        }
if inside if .. if in functional scope
javascript;json
Good formatting helps a lot:if (resp['soapenv:Envelope'] &&    resp['soapenv:Envelope']['soapenv:Body'] &&    resp['soapenv:Envelope']['soapenv:Body'][0] &&    resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'] &&    resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0] &&    resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0]['sevReturn'] &&    resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0]['sevReturn'][0]) {  var sev = resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0]['sevReturn'][0]['sev'];  if (sev) {    // TODO: built json  }}To get rid of repeated property access, you could use this pattern: var sev = (((((((resp || {})['soapenv:Envelope'] || {})['soapenv:Body'] || [])[0] || {})['p5:sevResp'] || [])[0] || {})['sevReturn'] || [])[0];if (sev) {  // TODO: built json}Or, if your response would only exceptionally miss any of these properties, handle the occasional exception:try {  var sev = resp['soapenv:Envelope']['soapenv:Body'][0]['p5:sevResp'][0]['sevReturn'][0]['Sev'];  if (sev) {    // TODO: built json  }} catch (e) {  if (e instanceof TypeError) {    // TODO: handle missing properties  } else {    throw e;  }}Also check the other answers to this question and use a library function if available such as lodash's _.get.