Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jyotiarora2610/769f0e0643a9dbbf76b27822a3e7b871 to your computer and use it in GitHub Desktop.
Save jyotiarora2610/769f0e0643a9dbbf76b27822a3e7b871 to your computer and use it in GitHub Desktop.
var movieLists = [{
name: "New Releases",
videos: [{
"id": 70111470,
"title": "Die Hard",
"rating": 4.0
}, {
"id": 654356453,
"title": "Bad Boys",
"rating": 5.0
}]
}, {
name: "Dramas",
videos: [{
"id": 65432445,
"title": "The Chamber",
"rating": 4.0
}, {
"id": 675465,
"title": "Fracture",
"rating": 5.0
}]
}]
var flattenArr = []
Array.prototype.concatAll = function(){
var output = []
this.forEach(function(item) {
if (Array.isArray(item))
item.forEach((result) => output.push(result))
else
output.push(item)
})
return output
}
flattenArr = movieLists.map(item => {
return item.videos.map(video => {
return video.id
// console.log(video.id)
})
}).concatAll()
console.log(flattenArr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment