I have props with following data
test1: abc
id: 1
myArray: Array(3)
0: {a:abc, b:cde, aid: 1}
1: {e:age, f:ade, aid: 2}
2: {t:are, h:had, aid: 1}
I want to filter props and update array to have only the values that match id and aid
So the props should look like below:
test1: abc
id: 1
myArray: Array(3)
0: {a:abc, b:cde, aid: 1}
2: {t:are, h:had, aid: 1}
How can i do that?
You can use the filter Array method
let myArray = [{a:"abc", b:"cde", aid: 1},
{e:"age", f:"ade", aid: 2},
{t:"are", h:"had", aid: 1}]
const result = myArray.filter(item => item.aid === 1)
console.log(result)
But take in consideration that props are immutable.
If you wish to change this prop permanently you will have to update it in the parent component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With