檢查JavaScript中的物件屬性是否未定義的最佳方法是什麼?
最佳答案
使用:
if (typeof something === "undefined") {
alert("something is undefined");
}
如果一個具有某些屬性的物件變數可以使用這樣的東西:
if (typeof my_obj.someproperties === "undefined"){
console.log('the property is not available...'); // print into console
}
相同標籤的其他問題
上一個問題:你如何處理巨大的if-state?
下一個問題:將多個int值比較為0的有效方法