简体   繁体   中英

How to compare 2 object in react JS and get the values

在此处输入图像描述

I have 2 state

 console.log(this.state.tempWilayahUser)
 console.log(this.state.wilayahUser)

how to get row when have same value of id_rt?

You can use filter() function to achieve this. You can read the docs here.

const state1 = [];
const state2 = [];

const itemsWithIdRtFromState1 = state1.filter(item1 => {
    return state2.filter(item2 => item2?.id_rt === item1?.id_rt)
});

const itemsWithIdRtFromState2 = state2.filter(item2 => {
    return state1.filter(item1 => item1?.id_rt === item2?.id_rt)
});

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