[英]JavaScript difference between console.log(string.length); and console.log([string.length]);
The section of code is代码部分是
var string = ['one','two','three'];
console.log(string.length-1);
console.log([string.length-1]);
Output:输出:
3
[ 3 ]
Can anyone tell me why my output is like this in the second scenario.It is a JavaScript code.谁能告诉我为什么我的输出在第二种情况下是这样的。它是一段 JavaScript 代码。
Square brackets returns an array.方括号返回一个数组。 Array definition like this : var arr = [1,2,3];数组定义如下: var arr = [1,2,3];
In your scenario console.log( [string.length-1] );在你的场景中 console.log( [string.length-1] );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.