For In Loops
The for...in
statement is primarily to iterate variables over the enumerable properties. For each property, the For In Loop executes specific statements. For In is best used for looping over objects. To loop over arrays, we often need to use the index, to get the value we want.
Put the following code in, and follow the practice objectives below.
// for in loops
for (var i /*variable section*/ in obj /*object section*/) {
console.log(i) /*statement*/
}
//Write a for in loop that capitalizes the first letter of studentName
var studentName = 'paul';
var capSN = '';
for (var n in studentName) {
if (n == 0) {
capSN = studentName[n].toUpperCase();
} else {
capSN += studentName[n];
}
}
Last updated