For Each in Javascript

Javascript dost not have for each feature but there is somthing like this.
Check out this function. It is equevalent foreach.

Javascript function


var array=new Object();
array[0]='Me';
array[1]='You';
var a1='Me'; a2='She'
function checkArr()
{
for(a1 in array)
alert('Yes');
for(a2 is array)
alert('No');
return false;
}

Check out demo here.

Demo :

 

0 comments: