Created
July 5, 2018 05:19
-
-
Save jyotiarora2610/769f0e0643a9dbbf76b27822a3e7b871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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