0

I'm using laravel validation request. I need to loop the object in the key "errors". Im using React, but just want understand how to loop it with JavaScript. This is the json object:

{  
   "message": "The given data was invalid.",
   "errors": {  
      "email": [  
         "The email field is required."
      ],
      "name": [  
         "The name field is required."
      ],
      "description" : [  
         "The description field is required."
      ]
   }
}

1 Answer 1

1

Use Object.keys which returns an array of object properties.

Object.keys(validation.errors).forEach(key => {
  console.log(validation.errors[key])
})
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I need to loop the errors object and get the message. Thanks
My answer does that exactly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.