I am trying to loop through my SharePoint list items retrieved using REST API but I get the following error:
Uncaught TypeError: Cannot read property 'ID' of undefined
function onQuerySucceeded(data) {
var items = data.d.results
console.log(items)
var listItems = ''
for (var x = 0; x <= items.length; x++) {
listItems += '<tr>'
listItems += '<td>' + items[x].ID + '</td>' //<---Error here
listItems += '<td>' + items[x].ID + '</td>'
listItems += '<td>' + items[x].ID + '</td>'
listItems += '<td>' + items[x].ID + '</td>'
listItems += '</tr>'
}
document.getElementById("service").appendChild(listItems)
}
Any help would be much appreciated.