在JavaScript中遍历非标准对象属性
我正在使用一个API,它通过AJAX向我返回响应,它在在JavaScript中遍历非标准对象属性,javascript,json,Javascript,Json,我正在使用一个API,它通过AJAX向我返回响应,它在responseJSON中返回响应,因此我使用点表示法访问我需要的对象部分,就像任何其他AJAX调用一样 var test = jqxhr.responseJSON.test; 对象的文字表示形式为: test = {1_status: "invalid", 4_type: "domain.com", 1_type: "alpha.domain.com", 4_email: "admin@domain.com", 3_email: "adm
responseJSON
中返回响应,因此我使用点表示法访问我需要的对象部分,就像任何其他AJAX调用一样
var test = jqxhr.responseJSON.test;
对象的文字表示形式为:
test = {1_status: "invalid", 4_type: "domain.com", 1_type: "alpha.domain.com", 4_email: "admin@domain.com", 3_email: "admin@charlie.domain.com"…}
在控制台中的console.log(test)
我如何通过如下循环中的中的1\u email
键访问值
for (var i = 1; i <= 4; i++){
// access key values here like so:
//console.log(test.i_email);
// where the console should return admin@alpha.domain.com on the first interation
}
我得到以下信息:
Uncaught SyntaxError: Unexpected token ILLEGAL
我需要以[I]\u状态访问每个工件,因为我不知道确切的返回值和订单更改,不幸的是,我无法直接访问API
非常感谢您的帮助。您可以使用索引器来完成此操作
test[i + '_email']
你可以用索引器来做这件事
test[i + '_email']
你可以用索引器来做这件事
test[i + '_email']
你可以用索引器来做这件事
test[i + '_email']
这非常有效,我从未在test[I]
之外使用索引
,所以我甚至没有想到这一点。非常感谢:)在javascriptx[y]
中没有索引。这是属性访问。它工作得非常好,我从来没有在测试[I]
之外使用索引
,所以我甚至没有想到这一点。非常感谢:)在javascriptx[y]
中没有索引。这是属性访问。它工作得非常好,我从来没有在测试[I]
之外使用索引
,所以我甚至没有想到这一点。非常感谢:)在javascriptx[y]
中没有索引。这是属性访问。它工作得非常好,我从来没有在测试[I]
之外使用索引
,所以我甚至没有想到这一点。非常感谢:)在javascriptx[y]
中没有索引。这是财产访问权。