I am trying to create an array and add data to the beginning of it. Then with a for loop I print out all the data.
However, it prints an error, as Uncaught TypeError: Cannot read property 'title' of undefined.
var coords=new Array();
coords.unshift({tite:"sadsad asdds",artist:"Tik Taak"});
coords.unshift({title:"Heyyy sd",artist:"shahram"});
coords.unshift({title:"brahhh",artist:"Daniel"});
for(var i = 0; i <= coords.length; i++){
console.log(coords[i].title + " - " + coords[i].artist);
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
As you can see one of the items is printed as undefined. And I think thats the point the error is triggered.
Any idea how to solve it?
Thanks in advance