Are you providing the API key when you make the request or have you deliberately redacted it in the code you posted? Because can’t currently test this.
But you aren’t returning the data in the functions, you’ve even commented to that effect:
So when you go onto the next then in the chain, you’re passing it undefined instead of the data, and you can’t map over undefined. To be explicit:
fetch(something)
.then(data => {
/* The value of `data` should be some JSON that came back
* from `fetch` */
return data.json();
/* The return value is the result of parsing that JSON string
* to a JS object */
})
.then(data => {
/* the value of `data` is the return value of the last function
* So `data` here is the value you've got from JSON.parse-ing the
* response from your `fetch` call.
*/
return console.log(data);
/* the return value is undefined! */
})
.then(data => {
/* the value of `data` here is the return value of the last function,
* which was `undefined`, so `data` is `undefined`
*/
...
It’s a chain of functions. Take this data then do something to it then pass it to the next function then do something to it then pass it this the next function etc etc. Whatever the return value of the previous function is, that’s the input for the next one. If you return undefined from the previous function, that’s the input to the next one in the chain.
If you want to get some specific data from a function, return that specific data
I indeed want to return a single random element! But within the scope of the characters.
As my initial code returned all the kanji characters of the complete array. I want to random give only one of these with every refresh.