If you're not using the result, map isn't the right tool for looping through an array. Similarly, if you're mapping strings to values (el.resource.name to an object), an array isn't the correct object type to use. Just use a plain object, or a Map.
The reason your two assignments are conflicting is that the second time the condition is true, it overwrites the first object you've assigned. Instead, create an object, then add each property to the same object as necessary.
It's not clear what end result you're really looking for, but perhaps something like:
const obj = {}; // *** Object, not array
res.forEach((el) => { // *** forEach, not map
if (el.resource.name === "FORM01" && (el.name === "cost.ttl" || el.name === "cost.use")) {
// *** Get the existing object if any; create and store a new one if there isn't already one there
const entry = obj[el.resource.name] = obj[el.resource.name] || {};
// *** Add this property to it
entry[el.name] = el;
}
});
or you might use for-of:
const obj = {};
for (const el of res) {
if (el.resource.name === "FORM01" && (el.name === "cost.ttl" || el.name === "cost.use")) {
const entry = obj[el.resource.name] = obj[el.resource.name] || {};
entry[el.name] = el;
}
});