A7D*_*7DC 1 javascript arrays object reactjs
想象一下,我有一个这样的对象数组(虚拟代码):
const chosenBets = [{...}, {...}] // 2 items
Run Code Online (Sandbox Code Playgroud)
我想从数组中删除特定项目:
{id: 0, // is unique
label: 1,
odd: 1.33,
oddIndex: 0,
team_home: "Liverpool",
team_away: "Sheffield United",
matchCardIndex: 0,}
Run Code Online (Sandbox Code Playgroud)
现在该数组为:
const chosenBets = [{...}] // 1 items
Run Code Online (Sandbox Code Playgroud)
我将如何实现?
您可以使用数组 filter
const chosenBets = [{
id: 0, // is unique
label: 1,
odd: 1.33,
oddIndex: 0,
team_home: "Liverpool",
team_away: "Sheffield United",
matchCardIndex: 0
}, {
id: 1, // is unique
label: 1,
odd: 1.33,
oddIndex: 0,
team_home: "Liverpool",
team_away: "Sheffield United",
matchCardIndex: 0
}];
const filteredData = chosenBets.filter(item => item.id === 1);
console.log(filteredData);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47 次 |
| 最近记录: |