要素を配列にプッシュしようとしています。
編集
task.prototype.goTest=function(){
for(a = 0; a < test.length; a++) {
if(this.testnumber != test[a].number) {
//it will only loop 8 times under conditional statement
group = {
title: test[a].Title,
ID: test[a].ID,
contents: []
};
this.company.push(group);
this.testnumber = test.number[a];
}
//outside of if conditional statement.. it will loop 15 times
//i want every test[a].conetents get pushed to group.contents array.
//this.company is the final variable I need for this function...
group.contents.push(test[a].contents);
}
console.log(this.company);
}
しかし、私がするとき
console.log(this.company);
group.contents
各配列に 1 つの要素しかない 8 つの要素が表示されます。group.contents
理想的な状況は、配列内に 2 ~ 3 個の要素を持つ 8 個の要素を持つことです。
this は関数内のオブジェクトを参照します。私の問題を解決する方法はありますか?