Sometimes, we want to merge two JSON or JavaScript arrays in to one array.
In this article, we’ll look at how to merge two JSON or JavaScript arrays in to one array.
How to merge two JSON or JavaScript arrays in to one array?
To merge two JSON or JavaScript arrays in to one array, we use the concat
method.
For instance, we write
const finalArr = json1.concat(json2);
to call json1.concat
with the json2
array to return a new array with the entries of the json1
and json2
entries.
Conclusion
To merge two JSON or JavaScript arrays in to one array, we use the concat
method.