2025-04-25 js操作2个数组a和b,用数组b对应项的 某个值(number) 替换 数组a的 某个值(title)
const result = a.map((item, index) => { // 从指定项开始,例如第3项 if (index < 2) return item; // 从第3项开始,用数组b对应项的 某个值(number) 替换 数组a的 某个值(title) const bItem = b[index - 2]; if (bItem) { return { ...item, title: bItem.number }; } return item; }); console.log(result);

浙公网安备 33010602011771号