繁体   English   中英

如果元素在数组中有一个空值。 然后告诉所有下一项为假

[英]If the element has an empty value in the array. Then tell all the next items false

大家好。 我有一些问题。 我想在数组中找到第一个具有空值的元素并将所有其他元素设置为 fals。 我尝试了许多不同的选择。 但到目前为止,只有具有当前元素的变体有效。

 someArray.map(e: any, inex: any, a: any) => {

  if (e.instruction.length > 0) {
    return e.isEmpty = false
  }

  return ( someHtml)
}

试试这个代码。

const isNotEmptyFirstItem = someArray[0].instruction.length > 0;
const updatedArray = isNotEmptyFirstItem && someArray.map(item => item.isEmpty = false);
}

你可以用 updatedArray 做你想做的事。

const FuncToCheck = (el) => el === true
cosnt faindElemIndex = someArray.faindIndex((el) => FuncToCheck(el))
const setCheck = () => {
  if (indexOfMap > faindElemIndex) { return false } 
    else return true
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM