[Solved] Access first element of json array [duplicate]


Use Object.entries to iterate on the errors and fetch the message property

const obj = {
	"errors": {
		"product_name": {
			"message": "Product name is required",
			"name": "ValidatorError"
		},
		"category": {
			"message": "Category is required",
			"name": "ValidatorError"

		}
	}
};

const [,value] = Object.entries(obj.errors)[0];
console.log(value.message);

1

solved Access first element of json array [duplicate]