Check if object key exists within object

后端 未结 7 1787
终归单人心
终归单人心 2020-12-31 04:16

I\'m trying to take some data from an existing object and group it into a new one. The problem I am having is checking if the object key exists so I can either create a new

相关标签:
7条回答
  • 2020-12-31 05:16

    I have run into this pattern a lot, and what I end up doing is:

    if (object[key]) {
        //exists
    } else {
        // Does not exist
    }
    

    so I think in your case it will be:

    if (groups[group_key]) {
        // Exists
    } else {
        // Does not exist 
    }
    
    0 讨论(0)
提交回复
热议问题