Js an array with several empty items. Output

arr.forEach((item, idx) => {
        if (item == "") {
          switch (idx) {
            case 0:
              console.log("")
              break;
            case 1:
              console.log("")              
              break;
            case 2:
              console.log("")              
              break;
            case 3:
              console.log("")              
              break;
            case 4:
              console.log("")              
              break;
          }
        }
        
      })

now the output is to print out all the empty items. What I want to get is that even if all five item inputs are empty, there is only one printed result
. Any one will do. Excuse me, how can it be realized?

Nov.14,2021

var i = arr.findIndex(item => item == '')

then judge

according to I

const status = [
  '0',
  '1',
  '2',
  '3',
  '4',
  '5',
  '6',
]
arr.forEach((item, idx) => {
  if (item == '') {
    console.log(status[idx])
  }
})

like this?


let arr = ['', '', '']
let flag = false
arr.forEach((item, idx) => {
    if (item == '') {
        flag = true
    }
})
if (flag) {
    console.log('');
}

arr.find ((item, index) = > {console.log ("th" + (index+1) + "case"); return item =';});

Menu