compare Two array and result only the values

I need to filter an array of objects

const arrayOne = [
    {id: 33, name: "fruit"},
    {id: 157, name: "car"},
    {id: 193, name: "water"},
];

const arrayTwo = [33, 193];

I need only the names in an array (without the key)

Expected output

["fruit", "water"]

Answer

1) You can easily achive the result using Map

const arrayOne = [
  { id: 33, name: "fruit" },
  { id: 157, name: "car" },
  { id: 193, name: "water" },
];
const map = new Map();
arrayOne.forEach((o) => map.set(o.id, o.name));

const arrayTwo = [33, 193];
const result = arrayTwo.map((o) => map.get(o));

console.log(result);

2) You can also achieve the result using map and find

const arrayOne = [
  { id: 33, name: "fruit" },
  { id: 157, name: "car" },
  { id: 193, name: "water" },
];

const arrayTwo = [33, 193];
const result = arrayTwo.map((id) => arrayOne.find((o) => o.id === id)?.name);

console.log(result);