Вы можете использовать Object.values
:
function getLength(obj) {
return (Object.values(obj)).flat().length
}
console.log(getLength(obj)); // => 6
const obj = {
'Master Automotives': [
{
SparePartID: '43',
Name: 'Oil and Lubricants',
Price: '4500',
VendorID: '48',
CompanyName: 'Master Automotives',
Qty: 1,
TotalPrice: '4500',
},
{
SparePartID: '45',
Name: 'Lights',
Price: '2300',
VendorID: '48',
CompanyName: 'Master Automotives',
Qty: 1,
TotalPrice: '2300',
},
],
'Repair Solutions': [
{
SparePartID: '47',
Name: 'Steering Wheel',
Price: '1500',
VendorID: '60',
CompanyName: 'Repair Solutions',
Qty: 1,
TotalPrice: '1500',
},
],
'FiveStar Automotives': [
{
SparePartID: '51',
Name: 'Brakes',
Price: '234',
VendorID: '70',
CompanyName: 'FiveStar Automotives',
Qty: 1,
TotalPrice: '234',
},
{
SparePartID: '53',
Name: 'Clutch',
Price: '999',
VendorID: '70',
CompanyName: 'FiveStar Automotives',
Qty: 1,
TotalPrice: '999',
},
{
SparePartID: '55',
Name: 'LED',
Price: '288',
VendorID: '70',
CompanyName: 'FiveStar Automotives',
Qty: 1,
TotalPrice: '288',
},
],
};
function getLength(obj) {
return (Object.values(obj)).flat().length
}
console.log(getLength(obj));