Check first if data.allItems[type] exists.
if(data.allItems[type] && data.allItems[type].length > 0){ ID = data.allItems[type][data.allItems[type].length - 1].id + 1; } else{ ID = 0; } Check first if data.allItems[type] exists.
if(data.allItems[type] && data.allItems[type].length > 0){ ID = data.allItems[type][data.allItems[type].length - 1].id + 1; } else{ ID = 0; }