How to use For...in Statement in JavaScript
In this article I am going to explain about for...in Statement in JavaScript.
JavaScript For...in Statement
The for...in statement repeats a group of embedded statements for each element in an array. The for...in statement is used to iterate through the collection to get the information that you want, but can not be used to add or remove items from the source collection to avoid unpredictable side effects.
Syntax
for(variable in object)
{
//Statement that you want to execute
}
|
Example
<html>
<head>
<script type="text/javascript">
{
function myFunction() {
var x;
var str = "";
var Emp = { Name: "Raju", Add: "Delhi", age: 30 };
for (x in Emp) {
str = str +Emp[x];
}
document.write(str);
}
}
</script>
</head>
<body>
<button onclick="myFunction()">Click</button>
</body>
</html>
|
Output
Further Readings
You may also want to read these related articles: here
Ask Your Question
Got a programming related question? You may want to post your question here