-1

I know this has been asked a lot of times, but I cannot get it to work.

I have an empty array a

var a = [];

and an array with an object b

var b = [{
   title: 'test'
}]

I want to join them so a will look exactly like b. The idea is to do this inside a for loop so a would be added a new item each time.

By using a.concat(b), a results in an empty array.

Not sure what I am missing.

1
  • 1
    please add some use cases. and what you have tried. Commented Nov 17, 2016 at 14:34

2 Answers 2

4

Per Array.prototype.concat()

This method does not change the existing arrays, but instead returns a new array.

You need to assign this operation back to a

a = a.concat(b)

Sign up to request clarification or add additional context in comments.

Comments

1

You need to assign result of that call to a. a = a.concat(b)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.