JS Basic Tutorial
The for...in
loop is used to iterate over the enumerable properties of an object or an array. It loops through the keys (or property names) of an object.
for (key in object) { // Code to execute for each key }
key
: A variable representing the current key in the iteration.object
: The object (or array) whose enumerable properties you want to loop through.Try it yourself
Although it's not the best practice to use for...in
with arrays (use for
or for...of
instead), it is possible because arrays in JavaScript are also objects.
Try it yourself
You can use for...in
to loop through the indices of a string.
Try it yourself