JavaScript 到处都有一些有趣的怪癖。考虑这个怪癖,从这篇很棒的帖子中撕下来(感谢 M. Staveley 分享这个):
var colours = ['red', 'green', 'blue']
// is red really in the array?
console.log(colours.indexOf('red') > -1); // outputs true.
// remove red, it's going out of fashion!
delete colours[colours.indexOf('red')];
console.log(colours.indexOf('red') > -1); // outputs false
console.log(colours.length) // length is still three, remember it's javascript!
最后一行是我的错误。这个怪癖让我很好奇,什么是获取真实计数的优雅方式colours
?