Article Introduction: implements an iterator that iterates through an array or all members of an object. |
Implements an iterator that iterates through an array or all members of an object.
var each = function (obj, fn) {
+++++++++++ Answer Area +++++++++++
+++++++++++ the end of the answer +++++++++++
};
try{
var data1 = [4,5,6,7,8,9,10,11,12];
var data2 = {
"A": 4,
"B": 5,
"C": 6
};
Console.group (DATA1);
Each (data1, function (o) {
if (6 = = this)
return true;
else if (8 = this)
return false;
Console.log (o + ": \" "+ This +" \ ");
});
Console.groupend ();
/*------[Execution Results]------
1: "4"
2: "5"
4: "7"
------------------*/
console.group (data2);
&NBSP
Each (data2, function (V, n) {
if (5 = = this)
return true;
Console.log (n + ": \" "+ V +" \ ");
});
Console.groupend ();
/*------[Execution Results]------
A: "4"
C: "6"
------------------*/
}catch (e) {
Console.error ("Execution error, error message:" + E);
}