I have loop were I display 3 subsites, the count gets 3 when it finish and it display the last value
$(document).ready(function () { //Get the URI decoded URLs. hostweburl = decodeURIComponent( getQueryStringParameter("SPHostUrl") ); appweburl = decodeURIComponent( getQueryStringParameter("SPAppWebUrl") ); // resources are in URLs in the form: // web_url/_layouts/15/resource var scriptbase = hostweburl + "/_layouts/15/"; // Load the js files and continue to the successHandler $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest); }); // Function to prepare and issue the request to get // SharePoint data function execCrossDomainRequest() { // executor: The RequestExecutor object // Initialize the RequestExecutor with the app web URL. var executor = new SP.RequestExecutor(appweburl); executor.executeAsync( { url:appweburl +"/_api/SP.AppContextSite(@target)/web/webs?@target='" +hostweburl + "'", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: successHandler, error: errorHandler } ); } function successHandler(data) { var jsonObject = JSON.parse(data.body); var results = jsonObject.d.results; for (var i = 0; i < results.length; i++) { document.getElementById("Error").innerHTML = results[i].Title; } }