scrimba
Create an RPG game - Rob Sutcliffe
For Of and For In loops
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

For Of and For In loops
by
AboutCommentsNotes
For Of and For In loops
by
Expand for more info
index.js
run
preview
console
const emails = [
{ sender:"bill@microsoft.com", subject:"You need to upgrade windows!", date:"Sep 5" },
{ sender:"steve@apple.com", subject:"Looking for a new phone?", date:"Sep 4" },
{ sender:"elon@tesla.com", subject:"Your tickets to Mars enclosed", date:"Sep 4" },
{ sender:"elizabeth@theranos.com", subject:"The results of your blood test", date:"Sep 2" },
{ sender:"larry@google.com", subject:"Regarding your search history", date:"Sep 1" },
{ sender:"jeff@amazon.com", subject:"Best new books this week", date:"Aug 23" },
{ sender:"mark@facebook.com", subject:"You've been tagged in 12 new photos", date:"Aug 21" }
];

for(let i = 0; i < emails.length; i++) {
const { sender, subject } = emails[i];
console.log(subject);
}

let emailsHtml = '';


// replace the for loop to reduce the code
// which would work better: a 'for of' or 'for in'?
for(let i = 0; i < emails.length; i++) {

const { sender, subject, date } = emails[i];

emailsHtml += `
<div class="email">
<span>${sender}</span>
<span>${subject}</span>
<span>${date}</span>
</div>`;
}

document.getElementById("emails").innerHTML = emailsHtml;
Console
"You need to upgrade windows!"
,
"Looking for a new phone?"
,
"Your tickets to Mars enclosed"
,
"The results of your blood test"
,
"Regarding your search history"
,
"Best new books this week"
,
"You've been tagged in 12 new photos"
,
/index.html
-3:10