I want to find the minimum value like this example:
I was trying this method to find the minimum value in the row, but I couldn't:
let obj = [
{ 1: 47, 2: 89, 3: 9, 4:23},
{ 1: 97, 2: 1, 3: 30, 4:53},
{ 1: 40, 2: 25, 56: 19, 4:41},
];
let minimo = obj.map((a, b) => {
let aa = Object.values(a)
let bb = Math.min(...aa)
for (const key in b) {
if (b.hasOwnProperty(key))
b[key] = bb;
}
return a;
}, {});
obj.push(minimo);
console.log(obj)
To add an item to the end of each object in the chain with the minimum and an array at the end with the minimums per column.
If you wanted an object with the last column
for()
it would change a bit.I hope this helps you.
EDIT: in the array of objects you use as an example you have a weird number in a Key
{ 1: 40, 2: 25, **56**: 19, 4:41}
. It does not affect the function, it is only to clarify.