i am trying to test the timing function in javascript by having it loop through an array of strings and displaying each after a 3 second delay but when i call the function it does a weird pattern of only taking the first letter of the first string, then the second letter of the second string, and so on... if, say the fourth item in the array has no fourth letter it prints undefined. please help. thanks
function myFunc () {
setTimeout(function () {
var contacts = {
addressBook : [
{
'name' : 'Jane',
'email' : 'JaneDoegmail.com'
},
{
'name' : 'Meggie',
'email' : 'meggiegmail.com'
},
{
'name' : 'John',
'email' : 'johnDoegmail.com'
},
{
'name' : 'Paul',
'email' : 'paulgmail.com'
},
{
'name' : 'Bo',
'email' : 'bogmail.com'
}
]
};
var object = contacts.addressBook;
var i;
for (var i = 0; i < object.length; i++) {
var item = object[i];
var name = item.name;
var email = item.email;
document.write(name[i]);
};
if (i < 10) {
myFunc();
};
}, 3000)
}
myFunc();