代码:

let arr = [{id: 100, isTrue: true},{id: 101, isTrue: false}];
arr.forEach(item => {
  item.isTrue = item.isTrue ? '小程序' : '公众号';
});
console.log(arr);

输出结果为:

[{id: 100, isTrue: '小程序'}, {id: 101, isTrue: '公众号'}]

这段代码本身没有问题。

JavaScript 数组遍历修改:isTrue 为 true 时改为 '小程序',false 时改为 '公众号'

原文地址: https://www.cveoy.top/t/topic/oBjH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录