Vuejs computed property 'for loop' print all values, but returns only one value.
computed: {
orderedUsers: function () {
//console.log(this.bannerData)
//console.log(this.subBannerData[0].event_pi[0].id);
this.secondSubBanner = [];
for(let i=0; i<this.bannerData.length;i++){
this.subBanner = this.bannerData[i].pressInformation;
//console.log(this.subBanner.event_pi);
for(let j= 0;j<this.subBanner.length;j++){
this.secondSubBanner = this.subBanner[j].id;
console.log(this.secondSubBanner);// output: 257, 256, 254,261
}
}
return [this.secondSubBanner];
},
sortedArray(){
this.v = this.orderedUsers;
console.log(this.v);// output:261
}
Can someone tell me where is my mistake? Thank you.
[this.secondSubBanner]and not justthis.secondSubBanner? Also you don't appear to be usingthis.secondSubBanneras the array you declare it as. I don't see how you can be outputting a list of ids when you're assigning only one id at a time.this.secondSubBanner.push(this.subBanner[j].id);then you'll be appending to the listthis.secondSubBannerso that it returns the values as array and I can sortout the Json depending on this array values. Thank you for your spontaneous reply. It has helped me.