// Посчитать сумму по полю dimensions.width
const arr = [{
{
id: 1,
dimensions: {
width: 10,
height: 20,
},
},
{
id: 2,
},
{
dimensions: {
width: 10,
height: 15,
},
},
}]**Ответ
function dimensionsWidth(arr) {
const res = [];
for (let name of arr) {
if (typeof name?.dimensions?.width == "number") {
res.push(name.dimensions.width);
}
}
return res.reduce((acc, el) => {
acc = acc + el;
return acc;
}, 0);
}
console.log(dimensionsWidth(arr));