-3

I have two array like a = [1,2,3] and b = [2,5] and I want result like result = [5]

How can I do this?

adnan159
  • 7
  • 3
  • Hi! Welcome to StackOverflow! Please take a look at tour https://stackoverflow.com/tour to get a better understanding about https://stackoverflow.com/help/how-to-ask. Another good read: https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions?. Afterwards, please edit your question to add all the relevant code. – Mohit Sharma Sep 19 '22 at 12:50

1 Answers1

2

Use Array.prototype.filter

const a = [1,2,3]
const b = [2,5]
const unique = b.filter(e => !a.includes(e))

console.log(unique)
Konrad
  • 21,590
  • 4
  • 28
  • 64