2 ms·
In javascript: const stf = [ {name: "x", pets: [{type: "cat", name: "kitty"}, {type: "cat", name: "kitty2"}]}, {name: "y",
by hjntmp 6y ago
In javascript:
const stf = [
{name: "x", pets: [{type: "cat", name: "kitty"},
{type: "cat", name: "kitty2"}]},
{name: "y", pets: [{type: "dog"}]},
{name: "z", pets: [{type: "cat", name: "miau"}]},
];
const myTransform = ({ pets, name: ownerName }) => pets
.filter(({type}) => type === "cat")
.map(({ name: catName }) => ({ ownerName, catName }))
stf
.map(myTransform)
.flat()
.forEach(({ownerName, catName}) => console.log(`Cat ${catName} to ${ownerName}`))