[jQuery]$.eachを理解する
by tea4two
HTML
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
<div id="five"></div>
JavaScript
var arr = ["one", "two", "three", "four", "five"];
var obj = {
one: 1,
two: 2,
three: 3,
four: 4,
five: 5
};
$.each(arr, function () {
$("#" + this).text("Mine is " + this + ".");
return (this != "one");//one以外だったら止めとく
});
$.each(obj, function (i, val) {
$("#" + i).append(document.createTextNode(" - " + this));
console.log(val);
console.log(typeof val);
});