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":"[email protected]"
    }
  ],
  [  
    {  
      "ID":"450",
      "NAME":"Starnes, Mitch",
      "Email":"[email protected]"
    }
  ],
  [  
    {  
      "ID":"499",
      "NAME":"Cosby, Lance H",
      "Email":"[email protected]"
    }
  ]
]; 

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

employeeArray =[  
  {  
    "ID":"967",
    "NAME":"Dang, Lance D",
    "Email":"[email protected]"
  },
  {  
    "ID":"450",
    "NAME":"Starnes, Mitch",
    "Email":"[email protected]"
  },
  {  
    "ID":"499",
    "NAME":"Cosby, Lance H",
    "Email":"[email protected]"
  }
];

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

1
  • 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. Commented Jan 12, 2016 at 19:01

1 Answer 1

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);
}, []);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.