Push into one array

Hard to describe my issue. Basically I’m using .push() to push two sets of elements into an array. As a result, I get
allAnchors[0]
allAnchors[1]

Two get created. Is there any way to merge them together so I don’t have allAnchors[1]? I want to for loop over just allAnchors[0] and have it grab all anchors.

if(settings.firstTab  == 'level2') {
        allAnchors.push(
          $(this)
            .next(dropdownWrapper)
            .find(fsNavLevel2)
            .find("a")
        );
        if($(this).next(dropdownWrapper).find(pageDesc).find("a").length) {
          allAnchors.push(
            $(this)
              .next(dropdownWrapper)
              .find(pageDesc)
              .find("a")
          );
        }
        // for(var i=0;i<)
        // allAnchors[0][0].addClass("red");
      }

try with this code:

var arrayNew=allAnchors[0].concat(allAnchors[1]);

the method that I used is concat() https://www.w3schools.com/jsref/jsref_concat_array.asp

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.