0

I know its been a while, but how can we add something where it checks a2 to see of an object had been re-added that was in a1 and then update missing?

var a1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
var a2 = ['a', 'b', 'c', 'd'];

let missing = a1.filter(item => a2.indexOf(item) < 0);

console.log(missing); // ["e", "f", "g"]
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
Daniel Garvin
  • 33
  • 1
  • 6
  • Welcome to stackoverflow. First off, you should delete that 'answer' because it's not an answer, while we're at it delete the link here as well. Can you elaborate more on the goal, 2.) it's not clear what you mean by readding to Array 2, that was in Array1, like detect was moved from Array1 to Array2? 3.) **what have you tried?** – Iancovici Jan 04 '18 at 17:40
  • I have two arrays. I linked the the related stackoverflow question because it's solving the first part of my problem. I want to compare two arrays and store the difference in a third array. If an object is removed from the second array that was in the first then store that object in the third array. That works fine with the stackoverflow link that i provided. my problem is that if I re-add the object to the second array I need it to be removed from the third array. – Daniel Garvin Jan 04 '18 at 17:43
  • Iancovici I have edited my question and provided an example from the linked stackoverflow question. When a object is re-added to a2 that was in a1 I want to update missing. Does that make sense? – Daniel Garvin Jan 04 '18 at 17:51
  • No not really, it's not clear if you're trying create a third array with missing values, or you're asking about continuing to update third array everytime this happens. If the latter, then you'll have to provide more effort so it's clear how you're modifying Array1 and Array2. – Iancovici Jan 04 '18 at 17:54
  • Yes I am updating the third array every time this happens. I have the objects in a listbox that has an onChange event. So every time an object is checked or unchecked is fires off that change event . – Daniel Garvin Jan 04 '18 at 17:57

0 Answers0