jQueryの配列操作
eachとmap
mapつかっていこうや

jsconst ne = $('.sortable-product').map(function(idx) {
return {
productId: this.dataset.productId,
sortNo: idx
}
}).get(); // getが必要
const ne = [];
$('.sortable-product').each(function() {
ne.push({
productId: this.dataset.productId,
sortNo: this.dataset.sortNo
});
});
filterもある
複数checkboxからcheckが付いているもののみを取得する例
js$("input[type='checkbox']").filter(":checked")
uncheck
js$("input[type='checkbox']").filter(':not(:checked)')
someとかeveryはjquery内には定義されていないが、 $.makeArray(..)
を使うことで、jsのそれが使える
js $.makeArray($(...)).some(function(x) { ... })
似たものにtoArrayもある
js$(…).toArray().some(function(node) { … })
違い
toArray
jQueryのmethodである
適用後は、jsのarrayになる
makeArray
transforms any array like object to javascript Array.