foo in bar - 'in' operator javascript?

前端 未结 4 2168
庸人自扰
庸人自扰 2021-01-21 09:52

I recently read a tutorial on CSS browser feature detection... The end product was something like this...

var prefix = [\'Moz\', \'webkit\', \'O\', \'ms\', \'Kht         


        
4条回答
  •  悲哀的现实
    2021-01-21 10:27

    if (foo in bar) is used to check whether the value named foo is a property of the object bar. Since arrays are just specially treated objects, you are correct in assuming that it can be used to check for a value in an array.

    test_style = document.createElement('div').style returns an object with properties; since this is the case, you can use the foo in bar syntax to check it.

提交回复
热议问题