rashmi agar
3 posts
Mar 07, 2025
8:26 PM
|
I’ve been exploring different ways to javascript concat array, and I found that concat() is a popular choice. It seems simple enough, but I wanted to check if there are any gotchas I should be aware of.
For example, does this work as expected?
javascript Copy Edit let numbers = [1, 2, 3]; let moreNumbers = [4, 5, 6]; let allNumbers = numbers.concat(moreNumbers, [7, 8, 9]); console.log(allNumbers); // [1, 2, 3, 4, 5, 6, 7, 8, 9] Are there scenarios where concat() might not be the best approach? Would love to hear your thoughts on its efficiency compared to other methods like push() or spread syntax.
|