0
我想檢查密鑰是否存在於對象中,並且如果存在則返回密鑰的值。Javascript:如何檢查密鑰是否存在並返回密鑰的值
var user_right=user_rights.split(',');
var tbar=new Array();
Ext.each(user_right,function(val,index){
if(items.hasOwnProperty(val))
-->tbar.push(items.val)
});
console.log(tbar);
但'tbar.push(items.val)'不起作用我確信這不是正確的方法。 如何檢索值。 更新:很不幸,這是下面的代碼是不是工作壓力太大
if(items.hasOwnProperty(val)){}
請幫
這裏有一些_relevant_答案http://stackoverflow.com/questions/5113374/javascript-check-if-variable-exists-which-method-is-better,以及這裏http://stackoverflow.com/questions/7636789/in-javascript-is-there-an-easier三通對檢查-IF-A-財產的-A-財產存在 –