Javascript examples for Array Operation:Array of Object
flatten group Array and Objects
<html> <head></head> <body> <script> var arr = [/*from w w w. ja v a 2s .co m*/ { data: [{ artist: 'Artist' }, { artist: 'Artist2' }]}, { data: { artist: 'Artist3' } }, { data: [{ artist: 'Artist4' }]} ]; var flattened = []; arr.forEach(function (el) { if(Array.isArray(el.data)) { flattened = flattened.concat(el.data); } else { flattened.push(el.data); } }); console.log(flattened); </script> </body> </html>