私がこのような配列を持っているとしましょう:
var arr = [
{type:"orange", title:"First"},
{type:"orange", title:"Second"},
{type:"banana", title:"Third"},
{type:"banana", title:"Fourth"}
];
そして、これを同じタイプのオブジェクトを持つ配列に分割したいので、次のようにします。
[{type:"orange", title:"First"},
{type:"orange", title:"Second"}]
[{type:"banana", title:"Third"},
{type:"banana", title:"Fourth"}]
しかし、私はこれを一般的に行いたいので、オレンジまたはバナナを指定するifステートメントはありません
// not like this
for (prop in arr){
if (arr[prop] === "banana"){
//add to new array
}
}
考え?JQueryとアンダースコアはどちらも使用するオプションです。