Checking defined item in enum

This question already has an answer here:

  • How do I check if an object has a property in JavaScript? 22 answers

  • In this special case, you could access the property and if the result is falsey, then take the default property 99 .

    const getAttributes = id => uiElementAttributes[id] || uiElementAttributes[99];
    

    Otherwise, you could use the in operator, or the suggested Object#hasOwnProperty .

    链接地址: http://www.djcxy.com/p/27314.html

    上一篇: 检查是否已分配toString

    下一篇: 在枚举中检查定义的项目