使用 push() 后,数组被记录为一个数字 [英] After using push(), array is logged as a number

查看:38
本文介绍了使用 push() 后,数组被记录为一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一组要翻阅的图像.第一组需要降序,第二组需要升序,所以我写了这个:

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();

}

当我将第二组推送到第一组时,它会将数组记录为 4,即使整个数组中有 6 个项目.

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.

如果我在用较大的孩子填充数组后记录数组,它会返回 HTML 对象,我希望在我推送较新的孩子后看到这些对象.

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.

有什么建议吗?

推荐答案

Array.prototype.push 返回数组的新长度.它修改原始数组.删除前面的 flipArray =.

Array.prototype.push returns the array's new length. It modifies the original array. Remove the flipArray = before it.

这篇关于使用 push() 后,数组被记录为一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆