0

I have two arrays,

var existingArray = [10,20,30,40];
var newArray =[10,20,30,40,50,60,70];

I want to extract non unique elements by using filter from above two arrays and output should be

var updatedArray =[50,60,70];

I am using javascript es6

sourabhk
  • 15
  • 4
  • If `newArray` is `[10,20,30,40,50, 50,60,70]` (has two 50s), then should `50` still be included in the output array? Or are you just after getting the difference between your two arrays? – Nick Parsons Dec 24 '22 at 08:43
  • no. neither existingArray nor newArray would have duplicate elements.all elements would be unique ids – sourabhk Dec 24 '22 at 08:45
  • Also, if `existingArray` array is `[10,20,30,40,80]` should `80` be included in the output? – Nick Parsons Dec 24 '22 at 08:45
  • Does this help? updatedArray = newArray.filter( (element) => { return !existingArray.includes(element); } ); – HamidYari Dec 24 '22 at 09:00

0 Answers0