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-财产存在 –