Uncaught TypeError: Cannot read property - Though property exists
<pre><code>var sorted = DocumentListData.Documents.sort(function (a, b) {
    var nameA = a.Document.toLowerCase(),
        nameB = b.Document.toLowerCase();

    return nameA.localeCompare(nameB);
});

for (var i = 0, len = sorted.length; i &lt; len; i++) {

    if (sorted[i].Document=== 'abc') {
        sorted.splice(i, 1);
    }

    if (sorted[i].Document=== 'xyz') {
        sorted.splice(i, 1);
    }
}
</code></pre>

<p>I am just breaking my head for one hour on what is the mistake going here. It throws me Document is undefined, though the Document property exists. </p>

<p><code>Uncaught TypeError: Cannot read property 'Document' of undefined</code>. When i remove the <code>sorted.splice(i,1)</code>, it works and there is no error. </p>
