![](/img/trans.png)
[英]Element of array is defined in console.log, but not in return statement
[英]console.log return specific element
我有一个javascript函数,它返回以下输出:
[ TextCommand { _textPattern: 'ping', _handler: 'pingCommand' } ]
使用console.log
时如何直接输出文本“ ping”?
我尝试并失败了:
console.log(entry._commands.TextCommand._textPattern);
仅供参考:
console.log(entry._commands);
将输出:
[ TextCommand { _textPattern: 'ping', _handler: 'pingCommand' } ]
是否必须解析或字符串化才能得到结果?
看起来_commands
属性是一个数组(不是对象),因此应获取其第一个元素(0)才能获得_textPattern
属性。
console.log(entry._commands[0]._textPattern);
//entry._commands是一个包含对象console.log(entry._commands [0] ._ textPattern);的数组。
尝试使用
console.log(entry._commands[0]._textPattern);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.