如何在javascript中基于键分隔值?

时间:2015-05-12 06:17:33

标签: javascript

此代码用于打印操作键值:

result [  
    { action: 'test' },
    { action: 'tests' },
    { action: 'tested' } 
];   
for (value = 0; value <= result.length; value ++) {
    response = this.actions[value]['action'];
    alert("Actions are: " + response); 
}

但是,它会导致错误:action cannot be a read property

1 个答案:

答案 0 :(得分:1)

代码中的操作未定义, 试试:

result =  [  {action: 'test'},
       {action: 'tests'},
       {action: 'tested'} ];  

for(value = 0; value <=result.length; value ++) {
    response = this.result[value]['action'];
   alert("Actions are: " +response); }