js对象找到数组中相同参数插入替换原来的

2024年08月01日 建站教程

//数组
var grapeList = [
    { score: '', color: '1111', checkDate: "1" },
    { score: '', color: '', checkDate: "2" },
    { score: '', color: '', checkDate: "3" },
    { score: '', color: '', checkDate: "4" },
    { score: '', color: '', checkDate: "5" },
];

//对象
var setGrapeInfo={score:'60',color:'yellow',name:'1234',checkDate:"1"};

//插入替换
grapeList = grapeList.map(t => {
    return t.checkDate === setGrapeInfo.checkDate
        ? setGrapeInfo
        : t;
});

//输出
console.log("grapeList",grapeList);

本文链接:http://so.lmcjl.com/news/9703/

展开阅读全文