0

I have two comma-separated strings

list1 = 6,2

list2 = 1,2,4,5,6,7,9,12,13

I want to remove list1 elements from list2

Is there any function or anything that can achieve my desired result.

Yevhen Horbunkov
  • 14,965
  • 3
  • 20
  • 42
Tony Zhao
  • 71
  • 1
  • 7

1 Answers1

2

Split into separate items, filter and join:

const list1 = '6,2',
      list2 = '1,2,4,5,6,7,9,12,13',
      
      result = list2
                  .split(',')
                  .filter(n => 
                    !list1
                      .split(',')
                      .includes(n))
                  .join(',')
                  
console.log(result)
Yevhen Horbunkov
  • 14,965
  • 3
  • 20
  • 42