Future You Sale
kh logo
All Courses
  1. Tutorials
  2. Web Development

for…in loop

Updated on Sep 3, 2025
 
8,081 Views

The JavaScript for…in loop is used to iterate over properties of Objects. In JavaScript, Arrays are also Objects and each character in a string have an index. So, we can use them also to iterate over Arrays and Strings.

//Object example
const obj = {
a: 1,
b: 2,
c: 3,
d: 4
}
for (const key in obj) {
console.log( obj[key] )
}

// Output:

1 2 3 4
//Array example
const array = ['a', 'b', 'c', 'd'];
for (const index in array) {
console.log(array[index])
}

// Output:

a b c d
//String example
const string = 'Web Developer';
for (const index in string) {
   console.log(string[index])
}

//Output:

W e b D e v e l o p e r
+91

By Signing up, you agree to ourTerms & Conditionsand ourPrivacy and Policy

pattern
15% OFF
Coupon Code "SELF15"
Coupon Expires  30/03
Copy
Get your free handbook for CSM!!
Recommended Courses