Languages

JavaScript - replace elements in array with elements of another array

0 points
Asked by:
Mikolaj
519

How can I replace elements in array with elements of another array?

For example, I have two arrays:

I want to replace all the elements from index 0 in array1 with the elements of array2.

The result should be:

How can I do that? 

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can use splice() method to do so.

Practical example

 

See also

  1. JavaScript - replace element in array

  2. JavaScript - replace many elements in array

References

  1. Array.prototype.splice() - JavaScript | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join