When I do console.log(msg);. My response is this [{"test":"aaaaa"}].
Now, How do I select aaaa.
When I do console.log(msg);. My response is this [{"test":"aaaaa"}].
Now, How do I select aaaa.
From Is there any key/value pair structure in JavaScript?
var myobj = {
"managaner": ["Prateek","Rudresh","Prashant"],
"employee": ["namit","amit","sushil"],
"hr": ["priya","seema","nakul"]
}
alert(myobj['employee'][1]); // Outputs "amit"
Try this:
$.each(msg, function(i, item){
console.log(item.test);
});
If you are getting your json response from some server or webservice then use it this way in your ajax success function(){}.
What going on with this is you have a json response as in array, so here $.each() is looping through the response it got from server then getting in the function with param item which is looping through the object. so at last console.log(item.test) is printing the object's property.
I understand that msg=[{"test":"aaaaa"}]
then u will have to take the value as msg[0].test . Then u can get "aaaaa"