【发布时间】:2019-01-03 03:25:41
【问题描述】:
例子:
let a = [1, 2]
console.log(a * 2); // NaN, this isn't Python
a = [3];
console.log(a); // an array, as expected: [3]
console.log(a * 2); // 6!
这恰好在实践中对 Headers 对象很有用,这些对象通常包含 1 个元素的数组:
// calculate when an API will reset its rate limit
new Date(response.headers['x-rate-limit-reset'] * 1000)
但是为什么它会起作用呢?
【问题讨论】:
标签: javascript arrays type-conversion