-1

How to merge two Large Array into one single Array.

Array is in nested form like -

Array_1 = [["",""],["",""],["",""],....]
Array_2 = [["",""],["",""],["",""],....]

the size of each Array is about 25mb.

Harry
  • 131
  • 1
  • 1
  • 8
  • `merged = [...Array_1, ...Array_2]` to combine the two – Nick Parsons Jan 30 '19 at 11:41
  • 1
    You...combine them. `.concat` or a `for` loop can do that. If you have any other requirements, you have to make them clear. – VLAZ Jan 30 '19 at 11:41
  • I have tried array.concat and for loop but its not giving me desired result, may be because of array size. – Harry Jan 30 '19 at 11:44
  • Possible duplicate of [How to merge two arrays in JavaScript and de-duplicate items](https://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items) – Jota.Toledo Jan 30 '19 at 11:45
  • I need to merge nested array like [[["":""],["":""]],[],[],....] – Harry Jan 30 '19 at 11:47
  • Your example of the needed result (`[[["":""],["":""]],[],[],....]`) is confusing: it has invalid syntax. Can you make more clear example of the needed result? – vsemozhebuty Jan 30 '19 at 14:22

1 Answers1

1

The ES6 way (https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/Spread_operator):

let newArray = [...Array_1, ...Array_2];

the old school way:

let newArray = Array_1.concat(Array_2);
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • This solution didn't work for me.I need to merge two nested array like [[["":""],["":""]],[],[],....] – Harry Jan 30 '19 at 11:51
  • which one did you try? i am using the spread operator since many years, and it always worked fine for merging two array, no matter what´s inside. what node.js version are you using? – andyrandy Jan 30 '19 at 11:52
  • 1
    what means "did not work", what did the resulting array look like? i would rather use the ES6 way though, not the old one. – andyrandy Jan 30 '19 at 11:53
  • ...and use node.js 10, if possible. the spread operator should even work for arrays with node.js 5+ though, according to node green. – andyrandy Jan 30 '19 at 11:56