TypeError : Cannot read property 'slice' of undefined

My code is:

var dps = JSON.stringify(ReportArray[i].displaySettings);
dps = dps.slice(1, -1)
dps = dps.replace('"', "'").replace('"', "'");

When I load my html file I got this error:

Uncaught TypeError: Cannot read property 'slice' of undefined
    at Object.success (xfmerFramework.js:602)
    at c (jquery-1.9.1.min.js:3)
    at Object.fireWith [as resolveWith] (jquery-1.9.1.min.js:3)
    at k (jquery-1.9.1.min.js:5)
    at XMLHttpRequest.r (jquery-1.9.1.min.js:5)

Answers 1

  • JSON.stringify will return undefined if the input is undefined.

    >>> JSON.stringify(undefined)
    undefined
    

    Please check if ReportArray[i].displaySettings is defined ? does ReportArray[i] really contain the displaySettings property? etc.


Related Articles