Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created May 25, 2021 01:45
Show Gist options
  • Select an option

  • Save lotusirous/e08b840cd0ec73a44cfa07ab9dec0a36 to your computer and use it in GitHub Desktop.

Select an option

Save lotusirous/e08b840cd0ec73a44cfa07ab9dec0a36 to your computer and use it in GitHub Desktop.
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