zoukankan      html  css  js  c++  java
  • [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;
  • 相关阅读:
    SHELL[22]
    SHELL[15]
    SHELL[08]
    SHELL[12]
    SHELL[06]
    SHELL[24]
    SHELL[11]
    shell文件合并、去重
    SHELL[25]
    SHELL[14]
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6275303.html
Copyright © 2011-2022 走看看