Definition
The for.. in loop iterates over the enumerable properties of an object in a arbitrary order. For each different property the statements can be executed.
Syntax
- for(variable in object){
- ...........
- ...........
- ...........
- }
- variable will store the different property names of the object coming from each iteration.
- object is that object whose enumerable properties are iterated.
Example
- <script>
- function getObjectValues(obj) {
- for (var item in obj) {
- alert(obj[item]);
- }
- }
- var obj = { prop1: 12, prop2: 100, prop3: 'Bikash' };
- getObjectValues(obj);
- </script>
Join the conversation! Your thoughts help the community grow.