在节点repl中,Object.keys似乎工作得很好,返回一个键数组。
> Object.keys({id: 1})
[ 'id' ]
但像这样的数组函数包含无法正常工作。
> Object.keys({id: 1}).includes('id')
TypeError: Object.keys(...).includes is not a function
at repl:1:22
at REPLServer.defaultEval (repl.js:248:27)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:412:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
这导致我检查类型和惊喜!它是一个对象。
> typeof(Object.keys({id: 1}))
'object'
有谁知道为什么会这样?如何从Object.keys获取数组?