简体   繁体   English

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

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

Hellow All.大家好。 I heve some issue.我有一些问题。 I want to find in an array the first element with an empty value and set all other elements to fals.我想在数组中找到第一个具有空值的元素并将所有其他元素设置为 fals。 I've tried many different options.我尝试了许多不同的选择。 But so far, only the variant with the current element works.但到目前为止,只有具有当前元素的变体有效。

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

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

  return ( someHtml)
}

Try this code.试试这个代码。

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

And you can do what you want with the updatedArray.你可以用 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