js如何判断 数组后一个的某值是不是false

test= [
  {
    "id": 1,
    "name": "Safa",
    "email": "neerupeeru@mail.ee",
    "purpose": "thesis",
    "programme": "Software Engineering",
    "year": 2016,
    "language": "Estonian",
    "comments": "In need of correcting a dangling participle.",
    "status": true
  },
  {
    "id": 2,
    "name": "Safa",
    "email": "neerupeeru@mail.ee",
    "purpose": "thesis",
    "programme": "Software Engineering",
    "year": 2016,
    "language": "Estonian",
    "comments": "In need of correcting a dangling participle.",
    "status": false
  },
  {
    "id": 3,
    "name": "Salman",
    "email": "neerupeeru@mail.ee",
    "purpose": "thesis",
    "programme": "Software Engineering",
    "year": 2016,
    "language": "Estonian",
    "comments": "In need of correcting a dangling participle.",
    "status": true
  }
];

我想去判断下一个的status是false的话,就做某些事

例如 循环跑到第一个,然后发现下一个对象的status是false,就console.log("下一个是false")

卡在抓不到下一个的status

该怎么实现?

阅读 2.5k
1 个回答

你都说了,循环看下一个,这个代码挺直白的吧?

for (const i = 0;i < test.length;i++) {
  if (i + 1 < test.length && !test[i + 1].status) console.log("下一个是false")
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏