I am working on a Gutenberg block and am modifying the Edit.js file. I want to fetch the root categories in the database. From the reading I have done, it seems a good way to do this is to use the REST API and perform a call like this:
var categories = fetch("http://localhost/wordpress_ttm/wp-json/wp/v2/categories")
.then(response => response.json())
This all works fine and gives me back a response. Here is the structure of the response.
categories: Promise { "fulfilled" }
<state>: "fulfilled"
<value>: (10) […]
0: {…}
1: {…}
2: {…}
3: {…}
4: {…}
5: {…}
6: {…}
7: {…}
8: {…}
9: {…}
length: 10
<prototype>: []
<prototype>: Promise.prototype
How do I to get the data out of the response? I want to grab the array data and iterate over it, but I'm not sure how to do that.