[RESOLVED]Empty Array after looping in it

    function (response) {
        $("#test").html(response);
        var ArrayofURLS = [];
        var UrlsHttpLess = [];

        toLengthgetUrl = $('.ProductTile').attr('href');

        var ClassURLLength = toLengthgetUrl.length;

        for (var i = 0; i < ClassURLLength; i++) {
            var getUrl = $('.ProductTile').eq(i).attr('href');
            ArrayofURLS.push(getUrl);
            //            var reducedstr = ArrayofURLS[i].subStr(7);


        }
        alert(ArrayofURLS);
        //        for (var j = 0; j < 2; j++) {
        //        ArrayofURLS[0].replace("http://", '');

        for (var j = 0; j < ClassURLLength; j++) {

            var cutItOf = ArrayofURLS[j].substr(7);
            UrlsHttpLess.push(cutItOf);
     
        }
        $('#test').append(UrlsHttpLess);
        alert(UrlsHttpLess);

Here is the code: Simply: I iterate after first tab – ArrayOfUrls and after exiting from the loop I can show the whole Array in  alert.
But, when I do second iteration where I add to UrlsHttpsLess tab elements as above, alert doesnt give anty result then. (same with append to test)

What am I doing wrong? In the loop (with var j)  UrlsHttpLess tab can be shown with expected result, but I want to have it after exiting from the loop…

Hi,

Check in your browser is it throwing any js error (check it in console in Dev Tools – F12)

What i know, u can’t append JS object to Html, so below code seems wrong:

kunhmateo93

$('#test').append(UrlsHttpLess);

Leave a Reply