Skip to content

Instantly share code, notes, and snippets.

@nguyenit67
Created June 29, 2021 05:47
Show Gist options
  • Save nguyenit67/99d3c3265f46156c0c7389afcfb65830 to your computer and use it in GitHub Desktop.
Save nguyenit67/99d3c3265f46156c0c7389afcfb65830 to your computer and use it in GitHub Desktop.
Array.prototype.flatMap()
let arr1 = ["it's Sunny in", "", "California"];
arr1.map(x => x.split(" "));
// [["it's","Sunny","in"],[""],["California"]]
arr1.flatMap(x => x.split(" "));
// ["it's","Sunny","in", "", "California"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment