0

I'm trying to create a multi-dimensional array but for some reason only the last value is returned instead of a 10-items array.

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

Output in console:

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

What am I doing wrong?

1
  • 2
    a.push = (arr);??? Commented Nov 4, 2018 at 13:23

1 Answer 1

2

push is a array method but you are using it (assigning value) as if it is a property of the array.

Change

a.push = (arr);

To

a.push(arr);
Sign up to request clarification or add additional context in comments.

1 Comment

Gosh... don't know how I missed that. Will mark as the correct answer. Thank you sir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.