In Javascript, How to determine if an object property exists and is not empty?

前端 未结 4 1160
萌比男神i
萌比男神i 2020-12-31 04:28

Suppose I have the next javascript object:

var errors = {
    error_1: \"Error 1 description\",
    error_2: \"Error 2 description\",
    error_3: \"\",
             


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 04:52

    In order to check whether the object is empty or not use this code.

    if (Object.keys(object_name).length > 0) {
    
      // Your code
    
    }
    

提交回复
热议问题