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"]
5
  • 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? Commented Jan 4, 2018 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. Commented Jan 4, 2018 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? Commented Jan 4, 2018 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. Commented Jan 4, 2018 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 . Commented Jan 4, 2018 at 17:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.