nested fetch api react native giving unpredictable response for custom operation <p>hi i am trying to fill array with custom data using multiple apis in react native but unable to do so as nested fetch api giving unpredicatable result my final array is always empty .</p> <p>Any help would be appreciated </p> <p>Thanks in advance below is my code please tell what i am doing wrong here..</p> <pre><code>fetchSubcategories(category_id){ var url=GLOBAL.BASE_URL+'/categories?filter[where][categoryId]='+GLOBAL.CATEGORY_ID+'&amp;filter[where][category_type]=subcategory&amp;filter[order]=name ASC'; const set = []; const subcategoriesArray=[]; fetch(url) .then((response) =&gt; response.json()) .then((responseData) =&gt; { for (var i = 0; i &lt; responseData.length; i++) { set.push(responseData[i]); } console.log('response subcategories : '+JSON.stringify(set,null,2)); }) .then(()=&gt;{ for(var j=0;j&lt;set.length;j++){ var name=set[j].name; var id=set[j].id; fetch(url) .then((response) =&gt; response.json()) .then((responseData) =&gt; { var subcategory={ name:name, id:id, products:[] } subcategoriesArray.push(subcategory); }).done() } }) .done() console.log('final custom josn array : '+JSON.stringify(subcategoriesArray,null,2)); } </code></pre> <p>Note : urls used above giving the proper result on my end the only thing is final subcategoriesArray should be filled.</p>