Skip to content
Advertisement

Vue Filter one array by an other array

Good morning, I have an array that looks like this:

JavaScript

Let’s just call it itemsDelegates. And then I have this one:

JavaScript

Now let’s call this addressvisibility. Now I’m trying to remove from itemsDelegates all entries that are already in addressvisibility. I tried the following approach:

JavaScript

Nevertheless, itemsDelegates still contains all entries. Where is my thinking error here?

Advertisement

Answer

filter returns a new array that only contains items matching the given criteria. It does not filter the array in-place. The simplest answer is to reassign the value of the array such that delegates = delegates.filter(...).

However, you could also combine addressvisibility.some and delegates.filter:

JavaScript

That will filter out any items in delegates where there are some (one or more) in addressvisibility where delegatesid matches.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement