[Javascript] Javascript 'in' opreator
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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); // 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的主要内容,如果未能解决你的问题,请参考以下文章
javascript JavaScript isset()等效: - JavaScript
JavaScript 使用JavaScript更改CSS(JavaScript)