1

I am trying to merge two Javascript objects (as shown below) with nodejs, cheerio and css selectors.

The objects are separate because they're being extracted from two different web pages and I cannot use asynchronous functions within my map function that is creating obj1.

Help with a solution or thinking through the process would be extremely helpful.

obj1 = [ 
  { position: 1, data: 'AAA' },
  { position: 2, data: 'BBB' }
]

obj2 = [
  { position: 1, review: 'abc' },
  { position: 2, review: 'def' }
]

output = [
  { position: 1, data: 'AAA', review: 'abc' },
  { position: 2, data: 'BBB', review: 'def' }
]
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • What type of approach have you tried? Can you show the code for your attempt? Also, do you know in advance that the properties you care about are named `data` and `review` or do you need a solution that supports any number of arbitrary properties? And, what happens if there are conflicts where there's more than one matching object with a given property or can you assume that will never happen? – jfriend00 Dec 26 '19 at 18:22
  • 1
    What does this have to do with CSS selectors? – Heretic Monkey Dec 26 '19 at 18:35
  • 1
    Thanks @HereticMonkey. The extend method is what I was missing. Appreciate it. – Blackfire52 Dec 26 '19 at 19:10

0 Answers0