After performing an ajax operation to retrieve data, I am using javascript to perform conditional checks. Here is the output when printing the response:
document.write(response)
Result:
[object Object]
When printing something like
document.write(JSON.stringify(response))
, the result is:
Result:
{"status":"failed","login":["This field is required."],"password":["This field is required."]}
Based on the above data, I am attempting to implement the following logic:
if(response.status === 'failed')
window.location.href = response.next;
else if ('login' in response && response['login']==["This field is required."])
{
$("#message").html(<p>Username is required</p>);
}
else if ('password' in response && response['password']==["This field is required."])
{
$("#message").html(<p>Password is required</p>);
}
However, the condition &&
with
response['login']==["This field is required."]
is not functioning as expected. How can I properly check the value in javascript?
Note: *New to javascript *