Why is 'for(var item in list)' with arrays considered bad practice in JavaScript?

前端 未结 5 898
醉酒成梦
醉酒成梦 2020-11-27 12:47

Given a simple zero based, numerically indexed array:

var list = [\'Foo\', \'Bar\', \'Baz\'];

Many times, I have noticed that when someone

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 13:35

    Add list.foo = bar; and try to use simple for. If you don't use some libraries(like prototypeJs) and don't add any new properties to array object - you can use simple for-statement.

提交回复
热议问题