JavaScript 'in' operator for `undefined` elements in Arrays

前端 未结 3 864
谎友^
谎友^ 2020-11-27 06:40

Please consider the following snippet of code:

> a = [1, undefined, undefined, undefined, 3]
  [1, undefined, undefined, undefined, 3]
> b = [1,,,,3]
          


        
3条回答
  •  天命终不由人
    2020-11-27 07:13

    //-1 means not in the list
    //['a','b','c'].indexOf('a') is return index if not find in the list then it give -1.
    
    if(['a','b','c'].indexOf('d') == -1)
    {
        console.log('yes it -1')
    }
    

提交回复
热议问题