javascript - Join array of objects -


I have asked this question before, but it seems that the solution does not work properly.

I have two objects:

  var a = [{x: 0, y: 0, color: "green", value: undefined, weight: 1} , {X: 0, y: 1, color: "red", value: undefined, weight: 1}]; Var b = [{x: 0, y: 0, value: 1}, {x: 0, y: 1, value: 3}];  

I want to include them in the same object, like:

  var c = [{x: 0, y: 0, color: " Green ", value: 1, weight: 1}, {x: 0, y: 1, color:" red ", value: 3, weight: 1}];  

Note: array A always has 25 entries, while not the array.

The proposed solution was: var extended = $ .extend ({}, A, B);

Although it creates an array of two entries, where not all values ​​are preserved.

I have also tried the following functions:

  var e = $ Merge (A, B); Var output = a.concat (b); Function jsonConcat (o1, o2) {for var key in o2} {o1 [key] = o2 [key]; } Return O1; } Var c = {}; C = jsonConcat (C, A); C = jsonConcat (c, b);  

Any help or push in the right direction will be greatly appreciated!

  function merge (a, b) {// a var result = a Do not want to change Piece (); For (var i = 0; i & lt; b.length; i ++) {for (in BR Atrima B [i]) {Result [i] [attrname] = B [i] [Attinam]; }} Return result; }  

The code has been taken from the accepted answer:


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -