Created
February 14, 2018 14:55
-
-
Save JoaoCnh/cc2267a72e6e5227caea4ede41459a53 to your computer and use it in GitHub Desktop.
Array of Arrays flatten with reduce
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
const mult = [songs, [{id: 112, name: "Chop Suey", artist: "System of a Down" }]]; | |
var flatMult = mult.reduce(function (acc, currValue) { | |
return acc.concat(currValue); | |
}, []); | |
// ES6 | |
const flatMult = mult.reduce((acc, currValue) => { | |
return acc.concat(currValue); | |
}, []); | |
console.log(flatMult); | |
// [ | |
// { id: 1, name: "Curl of the Burl", artist: "Mastodon" }, | |
// { id: 2, name: "Oblivion", artist: "Mastodon" }, | |
// { id: 3, name: "Flying Whales", artist: "Gojira" }, | |
// { id: 4, name: "L'Enfant Sauvage", artist: "Gojira" }, | |
// { id: 112, name: "Chop Suey", artist: "System of a Down" }, | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment