Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquerypush-to多维数组只返回最后一个值_Javascript_Jquery - Fatal编程技术网

Javascript jquerypush-to多维数组只返回最后一个值

Javascript jquerypush-to多维数组只返回最后一个值,javascript,jquery,Javascript,Jquery,我试图创建一个多维数组,但由于某些原因,只返回最后一个值,而不是10项数组 let a = []; $.each(IDs, function(index, value) { let au = $('#' + value + '.comment .user-name').text(); let av = $('#' + value + '.comment .profile-pic').attr('src'); let l = $('#' + value + '.comme

我试图创建一个多维数组,但由于某些原因,只返回最后一个值,而不是10项数组

let a = [];

$.each(IDs, function(index, value) {
    let au = $('#' + value + '.comment .user-name').text();
    let av = $('#' + value + '.comment .profile-pic').attr('src');
    let l = $('#' + value + '.comment .likes-count').text();
    let arr = [value, au, av, l];

    a.push = (arr);
});
console.log(a);
控制台中的输出:

[push: Array(4)]
push: (4) ["99", "John Baker", "template/images/avatars/fav3.svg", "20"]
length: 0
__proto__: Array(0)

我做错了什么?

push
是一种数组方法,但您使用它(赋值)时,就好像它是数组的属性一样

改变

a.push = (arr);


push
是一种数组方法,但您正在使用它(赋值),就好像它是数组的属性一样

改变

a.push = (arr);


a.push=(arr)???
a.push=(arr)???天哪。。。不知道我怎么会错过。将标记为正确答案。谢谢你,先生。天哪。。。不知道我怎么会错过。将标记为正确答案。谢谢你,先生。