-1

I need compare 2 arrays, 'a' and 'b' and to rescue the field that is not in 'a' array and save it in 'c' array

something like this:

let a = ['1', '2', '3']
let b = ['1', '2']

let c = a.compare(b)

c = ['3']
Matias Bertoni
  • 500
  • 2
  • 7

1 Answers1

0

Make a Set (contains unique values) and filter it to check that the values don't exist in either one of the arrays

let a = ['1', '2', '3']
let b = ['1', '2']

let co = [...new Set([...a, ...b])]

let c = co.filter(item => !a.includes(item) || !b.includes(item))

console.log(c)
LeoDog896
  • 3,472
  • 1
  • 15
  • 40