My javascript code like this :
<script type="text/javascript">
var team = [{id:"1", name:"chelsea"}, {id:"3", name:"mu"}, {id:"5", name:"arsenal"}];
for(var i = 0; i < 5; i++) {
if(team[i].id || typeof team[i].id !== 'undefined' || team[i].id !== null) {
console.log(team[i].id)
}
else {
console.log(i+1)
}
}
</script>
If the code run, on the console exist error like this :
Uncaught TypeError: Cannot read property 'id' of undefined
Whereas I had add condition if the variable not exist
How can I solve it?