Started by Teresa PortelaSep 14, 2021

Open
Multiple filters for arrays

0 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWES SHARE

I have 3 arrays. I want to return the elements in array1 distinct from array2 and array3. Example:

array1: ["Peter", "James", "JohnDoe", "Jackie"]
array2: ["James", "Dog"]
array3: ["JohnDoe", "Cat"]

Output: ["Peter", "Jackie"]

Here is my code snippet of filtering array2 out of array1.

 const array1, array2, array3;

const result = array1.filter(
element=> !array2.some(ele => element.id === ele.id)
);
// Output: ["Peter", "JohnDoe", "Jackie"]

I can think of creating another const for filtering array3, but is there a better/elegant way to attach the filters together?

0 Replies

You must be Logged in to reply
Trending Categories
15
Software39
DevOps45
Frontend Development24
Backend Development19
Server Administration17
Linux Administration24
Data Center24
Sentry24
Terraform21
Ansible29
Docker28
Penetration Testing14
Kubernetes16
NGINX19
JenkinsX17
Techiio

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

facebooklinkdeintwitter

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Copyright techiio.com @2020 Kolkata, India
made with by Abhishek & Priyanka Jalan
Copyright techiio.com @2020
made with by Abhishek & Priyanka Jalan