DEV Community

Cover image for How I generated a random response from a API
danielarmbruster0314
danielarmbruster0314

Posted on

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

Top comments (0)