'How to loop through array first and check and only execute else condition if all if conditions are false
{
created_time: '2022-04-15T04:51:32+0000',
message: 'Chapter 31 of BJ Archmage is out\n',
id: '××××××\'
},
{
created_time: '2022-04-15T04:49:43+0000',
message: 'Chapter 35 of Second Life on the Red Carpet is out\n',
id: '×××'
},
{
created_time: '2022-04-14T01:51:41+0000',
message: 'Damn',
id: '×××'
},
{
created_time: '2022-03-21T06:48:23+0000',
message: 'Uncle just got angry3',
id: '××××'
},
{
created_time: '2022-01-14T11:07:16+0000',
message: 'High-school Manhwa where mc is bullied at first but becomes stronger.,
id: '××××'
}
]
Above is the json I am getting using Facebook api when I try to loop through every message and compare it only compares one loop for the current title I want all the objects in array to loop through if conditions and only execute else condition if all if conditions were false if not then to break j loop there and continue i loop for getting next title and compare it again and so on....
const response = await axios("https://graph.facebook.com/v13.0/××××/feed?limit=5&access_token=×××××××);
const data = response.data;
for(var i=0;i<2;i++){
//some other codes.
//some other codes.
//some other codes.
for(var j=0;j<4;j++){
if(data.data[j].message.includes(getchap + " of " + chaptitle)){ //getchap and chaptitle changes every time I loop is executed
console.log(data.data[j].message);
console.log("post exist so skipping");
break;
}
else{
console.log("posted");
axios.post("https://graph.facebook.com/v13.0/××××××);
break;
}
}
}
Any help to me beginner would be appreciated. Thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
