JavaScript Concatenate 2 arrays with object in javascript / jquery concatenate arrays with different dimensions python,concatenate arrays with different

I have the following array

var x = [{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18}]

And i am trying to add the following array into it

var y = [{"id":"75769d11","title":"newtitle"}]

What i am trying to do is to merge somehow the 2 arrays into 1. The final array should be

[{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18},{"id":"75769d11","title":"newtitle"}]

Have tried

$.merge(x,y) 
// x.join(y) 
// x.push(y)   

javascript

x.concat(y)

Any idea would be useful. Regards

Answer:1
var x = [{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18}]
var y = [{"id":"75769d11","title":"newtitle"}];
var mergedArray=$.merge(x,y);
var mergedString=JSON.stringify(mergedArray);
console.log(mergedString);
Answer:2

var newArray=x.concat(y) will work.

With ES6, You can also use spread operator .... Spread operator turns the items of an iterable(arrays, array like objects) into arguments of a function call or into elements of an Array. So, to get new merged array you can do

var newArray=[...x, ...y]

If you want to merge the elements of x and y into x, you can still use spread operator as x.push(...y)

Answer:3

Well, Array.concat() method returns a new merged array. So, you have to store it in a variable to log it:

var x = [{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18}]

var y = [{"id":"75769d11","title":"newtitle"}]

var merged = x.concat(y);

console.log(merged);
Answer:4
var x = [{"id":"757382348857","title":"title","handle":"linkhere","productimage":"url","ippid":true,"location_x":26,"location_y":18}]

var y = [{"id":"75769d11","title":"newtitle"}]

var merged = x.concat(y);
Answer:5

An API I'm working with is returning poorly structured data like this: { "scsi0": "vm-101-disk-1.qcow2,size=32G", "scsi1": "vm-101-disk-2.qcow2,size=32G", "scsi2": "vm-101-disk-3.qcow2,...

An API I'm working with is returning poorly structured data like this: { "scsi0": "vm-101-disk-1.qcow2,size=32G", "scsi1": "vm-101-disk-2.qcow2,size=32G", "scsi2": "vm-101-disk-3.qcow2,...

My submit button is finally working. However, it is not counting all of the votes in the results. How do I get my submit button to sort all of the votes? HTML: <!DOCTYPE html> <html&...

My submit button is finally working. However, it is not counting all of the votes in the results. How do I get my submit button to sort all of the votes? HTML: <!DOCTYPE html> <html&...

  1. sort keys array php
  2. sort keys array javascript
  3. sort array keys
  4. sort array keys alphabetically php
  5. sort array keys descending php
  6. sort array keys js
  7. sort array keys descending order php
  8. sort array keys by value

I have two components: <div> <advertiser-add-component></advertiser-add-component> <advertisers-component></advertisers-component> </div> These components ...

I have two components: <div> <advertiser-add-component></advertiser-add-component> <advertisers-component></advertisers-component> </div> These components ...

I have a question whether this is possible or not. For example, there is one code like below. But that code has an error for sure. And I want to make if is true when one data is at some array. Could ...

I have a question whether this is possible or not. For example, there is one code like below. But that code has an error for sure. And I want to make if is true when one data is at some array. Could ...