Skip to content

Instantly share code, notes, and snippets.

@PatrickHeneise
Created January 31, 2019 13:39
Show Gist options
  • Save PatrickHeneise/96ccbf90be9dd02360da053d916a7279 to your computer and use it in GitHub Desktop.
Save PatrickHeneise/96ccbf90be9dd02360da053d916a7279 to your computer and use it in GitHub Desktop.
const a = [{ a: 'a' }, { a: 'b' }]
const b = ['1', '2']
const res = []
a.forEach(str => {
b.forEach(num => {
str.b = num
res.push(str)
})
})
console.log(res)
/**
* expected:
*
* [
* { a: 'a', b: '1' },
* { a: 'a', b: '2' },
* { a: 'b', b: '1' },
* { a: 'b', b: '2' }
* ]
*
* actual;
*
* [
* { a: 'a', b: '2' },
* { a: 'a', b: '2' },
* { a: 'b', b: '2' },
* { a: 'b', b: '2' }
* ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment