Hi I am new to react native,I am having a array of objects ,I want to delete the a inner object from this JSON.
[
{
Key: 1,
exchnageArr: [
{
name: ”FX”
},
{
name: ”MK”
}
]
},
{
Key: 2,
exchnageArr: [
{
name: ”CK”
},
{
name: ”DK”
}
]
}
]
Here I want to delete the {name:"FX"} from this JSON .If I pass "FX".How to do this,I tried but not working for me.
const newDatavalues = arr.forEach((item) =>
item.exchangeArr.forEach((subItem, index) => {
if (subItem.name === "FX") {
return item.exchangeArr.splice(index, 1);
}
})
);
2
Answers
You have a typo (
exchnageArr
, that should beexchangeArr
) in your property names in the array (JSON).Corrected JSON:
Now your code should work fine.
You could use
Array#filter
on each array inside one of the objects.