【JavaScript】hasOwnPropertyと配列

  • このエントリーをはてなブックマークに追加

配列はhasOwnPropertyを継承している。




var a = [1, 2, 3];
console.log(a.hasOwnProperty(1));// true
console.log(a.hasOwnProperty(4));// false
console.log(a.hasOwnProperty('length'));// true
console.log('------');
console.log(Array.prototype.hasOwnProperty.call(a, 0)); // true
console.log(Array.prototype.hasOwnProperty.call(a, 1)); // true
console.log(Array.prototype.hasOwnProperty.call(a, 2)); // true
console.log(Array.prototype.hasOwnProperty.call(a, 4)); // false
console.log(Array.prototype.hasOwnProperty.call(a, 'length')); // true
  • このエントリーをはてなブックマークに追加

SNSでもご購読できます。

コメントを残す

*