我有一個對象像下面,但我不知道如何檢查空狀態 我的目標,如何檢查空條件的對象
"general_info" : {
"parents_name" : "",
"date_of_birth" : "",
"second_day_attendance" : "",
"class_day" : "",
"reffered_by" : "",
"year" : "",
"amount_paid" : "",
"next_due" : "",
"payment_untill" : "",
"payment_made" : ""
},
if(general_info == ''){
alert('empty')
}
我知道我錯了,任何一個可以幫助我。謝謝。
// retrieve an Array of the keys of the named Object:
Object.keys(general_info)
// iterate over all the keys in the Array, using
// Array.prototype.every() to see if all keys
// match the supplied assessment:
.every(
// using an Arrow function to see if the current
// property-value of the named key of the Object
// is equal to a zero-length String:
key => general_info[key] === ''
);
你試圖檢查是否所有屬性都是空的? –