0

I am trying to access variable processStatus while using nodejs

JSON.stringify(result[0], null, 4) gives the following:

{
    "processingResult": "[{\"processStatus\": \"Successfully insert record\"}]"
}

I have tried

 if (result[0].processingResult[0].processStatus.indexOf('Successfully insert record') === -1)

but gives Error TypeError: Cannot read property '0' of undefined

this is a snippet of my code

  const result = await db.executeStoredProc(...);
  logger.info('Result[0]:     ' + JSON.stringify(result[0], null, 4));  //as above result
  if (result && result.length) {
    if (result[0].processingResult[0].processStatus.indexOf('Successfully insert record') === -1)
      throw new Error(`Error: ${result}`);
  }

Thanks in advance.

  • 1
    The `processingResult` value is a string, not an array, you'll need to parse it into an object first – CertainPerformance Mar 06 '21 at 21:36
  • I have tried if (result[0].processingResult.processStatus.indexOf('Successfully insert record') === -1) but gives the following error Error TypeError: Cannot read property 'processStatus' of undefined – kevster007 Mar 06 '21 at 22:19
  • @CertainPerformance would you be able to provid an example of what you mean? – kevster007 Mar 06 '21 at 22:40

0 Answers0