-3

I have an object like this:

let errorMessages = {
    firstName: [
      "It is too short",
      "Only English characters are valid"
    ],
    lastName: [
      "This field is required",
      "Only English characters are valid"
    ]
};

The result of Object.values(errorMessages) is:

[["It is too short", "Only English characters are valid"], ["This field is required", "Only English characters are valid"]]

But I want

["It is too short", "Only English characters are valid", "This field is required", "Only English characters are valid"]

How to achieve this?

S. Hesam
  • 5,266
  • 3
  • 37
  • 59

1 Answers1

1

You can use Array.flat that will concatenate all sub-arrays:

Object.values(errorMessages).flat()
elvira.genkel
  • 1,303
  • 1
  • 4
  • 11