Hi,
I have written a loop for the following “ducumentum” Array which is in employees var… but I am getting strange result, it is printing only the last one “Nagesh”.
Am I doing anything wrong here…? please help…
<script>
var employees = {“documentum”:[
{“firstName”:“Ravi”},
{“firstName”:“Murali”},
{“firstName”:“Nagesh”}
]
};
function employeesList(){
for(i=0; i<employees.documentum.length; i++){
var list = employees.documentum[i].firstName;
}
alert(list);
}
window.onload = employeesList;
</script>
Thank you so much for help…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<script>
var employees = {"documentum":[
{"firstName":"Ravi"},
{"firstName":"Murali"},
{"firstName":"Nagesh"}
]
};
function employeesList(){
for(var list=[],i=0; i<employees.documentum.length; i++){
list[i]=employees.documentum[i].firstName;
}
alert(list);
}
window.onload = employeesList;
</script>
</body>
</html>
Hi vwphillips,
Thank you so much… everything is working fine… Thanks a ton.
RAghavender