码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Javascript 'in' opreator

时间:2017-01-12 11:41:25      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:sid   console   eve   ber   color   const   nbsp   blog   eth   

If you want to check whether a key is inside an Object or Array, you can use ‘in‘:

 

Object:

const obj = {
  name: ‘GraphQL‘,
  watched: false
};

console.log(‘name‘ in obj); // true
console.log(‘title‘ in obj); // false

 

Array:

const characters = [
  ‘Harry Potter‘,
  ‘Ron Weasly‘,
  ‘Hermione Granger‘,
  ‘Nevel Longbottom‘,
  ‘Lavender Brown‘,
  ‘Scabbers‘,
  ‘Pigwidgeon‘,
]
console.log(0 in characters); // true;
console.log(6 in characters); // true;

 

[Javascript] Javascript 'in' opreator

标签:sid   console   eve   ber   color   const   nbsp   blog   eth   

原文地址:http://www.cnblogs.com/Answer1215/p/6275303.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!