Aggregating arrays using jQuery

Assuming jquery , all objects are as follows the arrays are of the same length and strictly follow the pattern denoted as follows:


Array 1

[
  {
    "Company": "Etsy",
    "Link": "https://angel.co/etsy?utm_source=companies"
  },

  ...

]

      

Array 2

[
  {
    "Market": "Handmade"
  },

  ...

]

      

Array 3

[
  {
    "Website": "http://www.etsy.com"
  },

  ...

]

      

Array 4

[
  {
    "Employee": "-"
  },

  ...

]

      

Array 5

[
  {
    "Stage": "-"
  },

  ...

]

      

Array 6

[
  {
    "Raised": "$97,250,000"
  },

  ...

]

      


Question:

What is jquery using the above arrays as input to get an array of the same length which schema is similar to below?


Array output

[
  {
    "Company": "Etsy",
    "Link": "https://angel.co/etsy?utm_source=companies",
    "Market": "Handmade"
    "Website": "http://www.etsy.com",
    "Employee": "-",
    "Stage": "-",
    "Raised": "$97,250,000"
  },

  ...

]

      

+3


source to share


1 answer


If they are all the same length, you can match the first array and expand the objects inside

var result = array1.map(function(o, i) {
    return $.extend({}, o, array2[i], array3[i], array4[i], array5[i], array6[i]);
});

      



FIDDLE

+5


source







All Articles