Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to get an array of some images to flip through. The first set need to be in descending order, while the second set need to be in ascending order, so I have written this:

var flipArray = [];

function createFlipArray(older, newer){

    flipArray = $("#"+older).children();

    flipArray = flipArray.get().reverse();

    flipArray = flipArray.push($('#'+newer).children());

    console.log(flipArray);


    loopThroughImages();

}

When I push the second set onto the first set, it logs the array as 4, even though there are 6 items in the whole array.

If I log the array after I populate it with the older children, it returns with HTML objects, which I expect to see after I push the newer children on.

Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
169 views
Welcome To Ask or Share your Answers For Others

1 Answer

.push modifies the array in-place. It does not return a new array, it returns the array's new length.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...