你瞅啥呢

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);

 

posted @ 2025-04-25 09:33  叶乘风  阅读(15)  评论(0)    收藏  举报