Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript map 2 array of objects

const people = [{id:1, name:"John"}, {id:2, name:"Alice"}];
const address = [{id:1, peopleId: 1, address: 'Some street 1'}, {id:2, peopleId: 2, address: 'Some street 2'}]

let op = people.map((e,i)=>{
  let temp = address.find(element=> element.id === e.id)
  if(temp.address) {
    e.address = temp.address;
  }
  return e;
})
console.log(op);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: onclick checkbox hide div and unchecked show div 
Javascript :: how to create a button with react 
Javascript :: window log scrollpostion 
Javascript :: js create element from string 
Javascript :: VM724:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 
Javascript :: jquery source disable right click 
Javascript :: angular add object to array 
Javascript :: vuex v-model 
Javascript :: p5.js add class to button 
Javascript :: javascript remove a specific item from an array 
Javascript :: react native android run 
Javascript :: python object to json 
Javascript :: how to show only few first elements of array js 
Javascript :: return first letter of string javascript in uppercase 
Javascript :: check if over 18 javascript 
Javascript :: convert number to string date js 
Javascript :: find all images without alternate text 
Javascript :: remove time from date javascript 
Javascript :: react image 
Javascript :: rgb to hex js 
Javascript :: move dom element to another parent 
Javascript :: document.write multiple lines 
Javascript :: javascript word count 
Javascript :: FileReader get filename 
Javascript :: add property to string js 
Javascript :: vue watch handler 
Javascript :: js check if two array have the same element 
Javascript :: vite install in vue 
Javascript :: js string array convert to int 
Javascript :: jest array contain object with prop 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =