如何访问数组的属性?

时间:2016-03-10 11:58:35

标签: javascript jquery arrays

我有这段代码

CODE JS:

this.on("success", function(file, responseText) {

    // from backend a response will be returned for every file uploaded
    var responseSuccess = [];
    $.each(responseText, function( index, value ) {
        responseSuccess.push(value.success );
        console.log(responseText["message: "+value.message ]);  //here
    });
});

该对象具有以下形式......我将图片更清楚地理解

enter image description here

我想在控制台中输入以下消息

"Sorry,there was an error uploading your file"

访问属性的正确方法是什么?

提前致谢!

1 个答案:

答案 0 :(得分:1)

您在消息和字符串连接之间感到困惑。你应该使用:

console.log(responseText["message"] + value.message);

现在有趣的部分是,responseText["message"]value.message都具有相同的值,因为您在这里迭代responseText。所以你要么:

console.log(responseText[0]["message"]); // OR
console.log(value.message);