简体   繁体   中英

how can i filter array of objects by its property value? in Javascript/ React-native

Plz help me masters. If I have data composed of objects, how can I filter them through their property value.

{id: 1, title: Tom, FinalTest: true}, 
{id:2, title: Maggie, FinalTest: false},
{id:3, title: Jake, FinalTest: true}

I want to filter object which propety FinalTest is true.

result

{id: 1, title: Tom, FinalTest: true}, 
{id:3, title: Jake, FinalTest: true}

May be this will help you:

 const test = [ { id: 1, title: "Tom", FinalTest: true }, { id: 2, title: "Maggie", FinalTest: false }, { id: 3, title: "Jake", FinalTest: true }, ]; const result = test.filter((t) => t.FinalTest === true); console.log(result)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM