0

Here i have a JSON object in an array and have it pushed to employeeArray which is

employeeArray =[  
  [  
    {  
      "ID":"967",
      "NAME":"Dang, Lance D",
      "Email":"Lance.Dang@xyz.com"
    }
  ],
  [  
    {  
      "ID":"450",
      "NAME":"Starnes, Mitch",
      "Email":"Mitchell.Starnes@xyz.com"
    }
  ],
  [  
    {  
      "ID":"499",
      "NAME":"Cosby, Lance H",
      "Email":"Lance.Cosby@xyz.com"
    }
  ]
]; 

How do i get this into a single array with JSON objects like this

employeeArray =[  
  {  
    "ID":"967",
    "NAME":"Dang, Lance D",
    "Email":"Lance.Dang@xyz.com"
  },
  {  
    "ID":"450",
    "NAME":"Starnes, Mitch",
    "Email":"Mitchell.Starnes@xyz.com"
  },
  {  
    "ID":"499",
    "NAME":"Cosby, Lance H",
    "Email":"Lance.Cosby@xyz.com"
  }
];

help me how to use above two dimensional array values and build my expected array in pure javascript

Adam Azad
  • 11,171
  • 5
  • 29
  • 70
eaglemac
  • 235
  • 1
  • 2
  • 12
  • 1
    Start by *learning*, for example, try googling "what is json" & "javascript array". Then think about what got you into this state you're trying to get out of. – Amit Jan 12 '16 at 19:01

1 Answers1

3

You want to flatten the array, which can be done with a reduce call:

employeeArray.reduce((p, c) => p.concat(c), [])

ES5:

employeeArray.reduce(function (p, c) {
  return p.concat(c);
}, []);
ssube
  • 47,010
  • 7
  • 103
  • 140