0

I have an ajax request that returns an array (data) :

{"errors":{"first_name":1,"last_name":1,"email":1},"error":1}

I used :

var obj = $.parseJSON(data);

I can check the error value using obj['error'] but now, I need to loop the errors array to add/remove an error class on each appropriate field. I don't know how to extract it and create the loop (with $.each, for instance). I have to mention I'm not supposed to know each key name, that's what I need to get.

Xavier C.
  • 1,809
  • 4
  • 24
  • 40

1 Answers1

0

Try to use $.each() to iterate over that object,

$.each(obj.errors,function(k,v){
  console.log(k,v); //Here k and v are keys and values
})
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130