6
How I generated a random response from a API
source link: https://dev.to/danielarmbruster0314/how-i-generated-a-random-response-from-a-api-3cb7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How I generated a random response from a API
function firstFetch(){
fetch('url')
.then((resp) => resp.json())
.then((data) => grabRandomId(data));
};
function grabRandomId(arry){
let newId = Math.floor((Math.random() * arry.length) + 1);
fetch(`url/${newId}`)
.then((resp) => resp.json())
.then((data) => console.log(data));
};
Enter fullscreen mode
Exit fullscreen mode
Any critiques on this are more than welcome
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK