Hello, world! I'm a professional self taught full-stack developer from Moscow. I truly love web-development and all that it concerns. Making websites is awesome. Follow me if you need some help
Arrays start from 0, meaning if you want the latest 2, you want to stop when the array key (the index of the array item) reaches 1. So you have 0, and 1. The API automatically orders by newest first, so we just need to tell it when to stop!
In the code above, simply change if ($key == 2){ break; } to if ($key == 1){ break; }
Hope that helps :) but let me know if you have anymore questions, or it doesn't make sense.
do we know how we can view the documentation for this API, in terms of query params and such. I'd like to filter out any article which has been archived, or is in Draft format. As when i hit the api, it seems it is returning archived posts aswell.
Is it possible to get only 2 latest posts?
Absolutely!
Arrays start from 0, meaning if you want the latest 2, you want to stop when the array key (the index of the array item) reaches 1. So you have 0, and 1. The API automatically orders by newest first, so we just need to tell it when to stop!
In the code above, simply change
if ($key == 2){ break; }
toif ($key == 1){ break; }
Hope that helps :) but let me know if you have anymore questions, or it doesn't make sense.
do we know how we can view the documentation for this API, in terms of query params and such. I'd like to filter out any article which has been archived, or is in Draft format. As when i hit the api, it seems it is returning archived posts aswell.
you can easily do that with this.
const latest2Post = postArray.slice(0, 2);