Это вернет первый элемент с "shipping": "ABC"
:
// convert response data to array of key-value pairs
const entries = Object.entries(response);
// reduce array to the first matching object
const reducer = (acc, [key, val]) => {
return (acc === null && val.shipping === "ABC") ?
(acc = { [key]: val }) : null;
};
// return the found object or null
const found = entries.reduce(reducer, null);
/*
{
'37': {
shipping_id: 37,
position: 0,
status: 'D',
shipping: 'ABC',
delivery_time: '24h-72h'
}
}
*/
Рабочий пример:
const res = {
"37": {
shipping_id: 37,
position: 0,
status: "D",
shipping: "ABC",
delivery_time: "24h-72h"
},
"36": {
shipping_id: 36,
position: 0,
status: "D",
shipping: "DEF",
delivery_time: ""
},
"28": {
shipping_id: 28,
position: 0,
status: "D",
shipping: "GHI",
delivery_time: ""
}
};
const entries = Object.entries(res);
const reducer = (acc, [key, val]) => {
return (acc === null && val.shipping === "ABC") ?
(acc = { [key]: val }) : null;
};
const found = entries.reduce(reducer, null);
console.log(found);