如何从对象数组中删除值" nissan"?
const cars = [
{type: "audi", amount: 2},
{type: "nissan", amount: 12},
{type: "mazda", amount: 5},
{type: "volvo", amount: 5}
]
这是我显示所有类型和金额的方式:
cars.map(car => {
return (
<div>{car.type}: {car.amount}</div>
);
});
但我希望在映射汽车之前删除价值&#34; nissan&#34;,我怎么能用.filter做到这一点?
removeNissan() {
// cars.type !== "nissan"
}
cars.filter(removeNissan).map(car => {
return (
<div>{car.type}: {car.amount}</div>
);
});
答案 0 :(得分:1)
在var jsVar=0;
function myFunction()
{
document.sampleForm.variable.value = jsVar;
document.forms["sampleForm"].submit();
}
功能
map
或者如果您想使用命名函数,请声明您的函数
const cars = [
{type: "audi", amount: 2},
{type: "nissan", amount: 12},
{type: "mazda", amount: 5},
{type: "volvo", amount: 5}
]
cars.filter(item => item.type !== 'nissan').map(car => {
return (
<div>{car.type}: {car.amount}</div>
);
});
filter会将每个项目作为参数传递给函数。