首页 > 代码库 > [Javascript] Javascript 'in' opreator

[Javascript] Javascript 'in' opreator

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); // trueconsole.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