sum values in an array based on another array

I am currently trying to sum some values in an array of objects, based on the Id of another array present in the current array. assuming I have this array

const queryArray = [ "1" , "2" ]

and this is the array I would like to sum if fees property values of the Id matches

const services = [
  {
    Id: "1",
    services: "Early Check-In",
    fees: "7500"
  },
  {
    Id: "2",
    services: "Late Checkout",
    fees: "7500"
  },
  {
    Id: "3",
    services: "Airport Chauffeur",
    fees: "25000"
  }
]

so I will like to get the sum of the fees property value in the services array up here based on the Id available in the queryArray. so in this case

[ "1" , "2" ]

should return

15000

if I decided to use this below

[ "1" , "3" ]

it should return

32500

and if also do

[ "1", "2" , "3"]

it should return

40000

Am new to javascript so I can’t even think of any possible solution or the step to take at all.

Answer

Sure, filter the services you need -> map service to it’s value -> reduce the resulting list to a singe number adding the elements:

const services = [
  {
    Id: "1",
    services: "Early Check-In",
    fees: "7500"
  },
  {
    Id: "2",
    services: "Late Checkout",
    fees: "7500"
  },
  {
    Id: "3",
    services: "Airport Chauffeur",
    fees: "25000"
  }
]
const ids = ["1" , "2"]

console.log(
  services
    .filter(({Id}) => ids.includes(Id))
    .map(({fees}) => parseFloat(fees))
    .reduce((acc, fees) => acc + fees, 0)
  
)