erasmo carlos
erasmo carlos

Reputation: 682

How to access to element in array

I am trying to figure out how to access the value of message "Meeting 9943...is not found or has expired"

I tried:

                if (response.data.status == 404) {
                    angular.element(document.getElementById("msg")).css("color", "red");
                    $scope.msg = response.data.message.message; <- this show undefined
                    console.log("Status Code= " + response.data.status + ", Status Text= " + response.data.message);
                    return false;
                }

watch

What is the correct method to access the value of response.data.message.message?

Thank you for your help

Upvotes: 0

Views: 38

Answers (2)

Daniel Garc&#237;a
Daniel Garc&#237;a

Reputation: 46

The value of the message is a string, you need to parse it with:

JSON.parse(response.data.message)

And after that, you can access to the property message inside the object.

Upvotes: 1

Adrian Brand
Adrian Brand

Reputation: 21638

That is the correct syntax, are you sure this debug snapshot is for the object you are getting the error on?

Try

$scope.msg = response.data.message && response.data.message.message;

this will not try and access the message for cases where the parent message object doesn't exist.

Upvotes: 0

Related Questions