for … in loop with string array outputs indices

前端 未结 4 490
孤城傲影
孤城傲影 2020-12-03 11:16

When I write some javascript such as this:

var words = [\'word1\', \'word2\', \'word3\']

for (word in words) {
    console.log(word)
}

The

4条回答
  •  广开言路
    2020-12-03 11:43

    1. for..in is used to iterate over the properties of a javascript object.
    2. Think of an array as a javascript object with indexes as properties.

提交回复
热议问题