Created
May 25, 2021 01:45
-
-
Save lotusirous/e08b840cd0ec73a44cfa07ab9dec0a36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 array1 = ["A", "B", "C"]; | |
| const array2 = ["1", "2", "3"]; | |
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce | |
| // acc is the Accumulator for our result, it starts with [] | |
| // for each element in array 1, we will use the add operator when `map` with each element in array 2. | |
| const result = array1.reduce( | |
| (acc, v) => [...acc, ...array2.map((x) => v + x)], | |
| [] | |
| ); | |
| console.log(result); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment