Find Maximum values in sub arrays

The given data looks like this:


const products = [
  {
    name: "car",
    subArr: ["4", "200", "599.4", "4444"]
  },
  {
    name: "tv",
    subArr: ["44477", "50", "579.2", "3232"]
  },
  {
    name: "glass",
    subArr: ["2121.1", "6347", "8867", "90.01"]
  }
];

We need to findout the maximum value out of all subArr

Solution

const maxArr = products.map(product => Math.max(...product.subArr));

const maxValue  = Math.max(...maxArr);
// output the maximum value