mapping betwen two array to match id

by 420

JavaScript

const entries = [
  {name: 'sanjog', age: 40, service: 3},
  {name: 'raj', age: 50, service: 3}
]
const services = [
  {id: 3, desc: 'this is desc'},
  {id: 4, desc: 'this is another desc'}
]

const data = entries.map(historyEntry => {
   // const service = find(services, {id:historyEntry.service}) this is for lodash
    const service = services.find(item => item.id = historyEntry.service)
    return {...historyEntry, service}
     });

console.log(data)