前端js 替换问题?

作者站长头像
站长
· 阅读数 9
"assessingOfficer": [
    {
        "AssessingOfficerName": "卡特琳娜",
        "AssessingStatus": 1,
        "AssessingOfficerType": 1,
        "dataTime": "2024-04-09 17:12:04",
        "remarks": "我们在一起",
        "UserName": "卡特琳娜"
    },
    {
        "dataTime": "2024-04-09 17:07:17",
        "remarks": "222222222222",
        "UserName": "卡特琳娜",
        "AssessingOfficerName": "卡特琳娜",
        "AssessingStatus": 2,
        "AssessingOfficerType": 2
    },
    {
        "dataTime": "2024-04-09 17:07:33",
        "remarks": "22222222222222",
        "UserName": "卡特琳娜",
        "AssessingOfficerName": "卡特琳娜",
        "AssessingStatus": 2,
        "AssessingOfficerType": 2
    }
]

前端js 替换问题?

怎么替换成红色的值 对象可能有多个

回复
1个回答
avatar
test
2024-06-19
const assessingOfficer = [
  {
    AssessingStatus: 2,
  },
  {
    AssessingStatus: 2,
  },
  {
    AssessingStatus: 1,
  },
  {
    AssessingStatus: 1,
  },
  {
    AssessingStatus: 2,
  },
  {
    AssessingStatus: 2,
  },
  {
    AssessingStatus: 2,
  },
];

var assessingOfficerArr = assessingOfficer.map((el) => el.AssessingStatus);

var deepAssessingOfficerArr = JSON.parse(JSON.stringify(assessingOfficerArr));

for (let i = 0; i < deepAssessingOfficerArr.length; i++) {
  if (i === 0)
    assessingOfficerArr[0] = deepAssessingOfficerArr[0] === 1 ? 3 : deepAssessingOfficerArr[0];
  if (i > 0)
    assessingOfficerArr[i] =
      deepAssessingOfficerArr[i] === 1
        ? 3
        : deepAssessingOfficerArr[i - 1] === 1
        ? 1
        : deepAssessingOfficerArr[i];
}

console.log('assessingOfficerArr', assessingOfficerArr);

answer image

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容