Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter object with multiple value in Javascript?

I am trying to return is (member: true) && names with the letter ‘K’?

<pre>
let people =  ([
{ name: "Angelina Jolie", member: true },
{ name: "Eric Jones", member: false },
{ name: "Paris Hilton", member: true },
{ name: "Kayne West", member: false },
{ name: "Bob Ziroll", member: true }
]);



let active = people.filter(iterator => (iterator.member == true && 
iterator.name.includes('K'))).map((iterador) => iterador.name);

console.log(active);
</pre>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If Kayne West would have member: true, then you will have result:

let people =  [
    { name: "Angelina Jolie", member: true },
    { name: "Eric Jones", member: false },
    { name: "Paris Hilton", member: true },
    { name: "Kayne West", member: true },
    { name: "Bob Ziroll", member: true }
    ];
    
    
    
    let active = people.filter(iterator => (iterator.member == true && 
    iterator.name.includes('K'))).map((iterador) => iterador.name);

    console.log(active)

Otherwise, none of the items are not satisfying condition in filter:

iterator.member == true && iterator.name.includes('K')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading