[Vuejs]-Intersect two json arrays and combine all fields without using explicitly naming fields to combine

1👍

Probably the simplest way to do this is to iterate the Company Pricing into a Map based on Part Num and then iterate the Product Info, using the Pricing Reference Name to lookup the appropriate pricing in that Map:

const products = {
  "Product Info": [
    {
      "ID": 1,
      "Fuel Source": "Wood",
      "Type": "Freestanding",
      "Model": "F1150",
      "Catalytic": "No",
      "Maximum BTU's Per Hour": 55000,
      "Higher Heating Value Efficiency (HHV)": 0.7,
      "Lower Heating Value Efficiency (LHV)": 0.75,
      "Steady-State Efficiency": "n/a",
      "Link To Unit": "http://www.regency-fire.com/en/Products/Wood/Wood-Stoves/F1150",
      "Key Features": "Large fire viewing area, with heat radiating ceramic glass\nWood-finished handle\nHeavy duty cast hinges that will never bend or break\nSolid forged steel adjustable cam lock ensures a tight door seal over time\nFront mounted air adjustment\nAir operating safety tool\nHigh performance brick-lined firebox reflects heat\nNon-obtrusive air wash curtain keeps glass clean\nHeavy gauge steel log retainers to stop logs from rolling\nWelded ash lip will never bend or break\nRear heat deflector allowing for closer clearances\nMobile home and alcove approved\nDual-burn design creates longer and more complete burns\nBacked by the industry’s most comprehensive Limited Lifetime Warranty",
      "Product Size": "Small",
      "Maximum Log Size": "18\"",
      "Burn Time*": "Up to 8 hours",
      "Firebox Capacity": "1.3 cu. ft.",
      "Hopper Size": "n/a",
      "Emissions (g/hr)": "1.7 g/hr",
      "View Area": "126 sq. in.",
      "Exhaust Size": "6\"",
      "Minimum Fireplace Opening (W x H x D)": "n/a",
      "Fireplace Dimensions (W x H x D)": "24\" x 32-3/16\" x 20\"",
      "Picture Name": "F1150.jpg",
      "Feature Sheet File Name": "F1150 Feature Sheet.pdf",
      "Description": "The Regency Classic Small Wood Stove is perfect for smaller spaces, or for those needing to supplement their current heating system. It's compact footprint does not disappoint in heating capacity; burning efficiently, and extracting all the heat possible from one load of wood. Turn down your furnace and save money with this Regency small wood stove.",
      "Teaser": "A perfect fit for smaller rooms.  This small non-catalytic wood stove, comes with your choice of pedestal or legs and it is available in black or with nickel accents.",
      "Additional Picture Name #1": "F1150-B.jpg",
      "Pricing Reference Name": "001-915"
    },
    {
      "ID": 2,
      "Fuel Source": "Wood",
      "Type": "Freestanding",
      "Model": "F2450",
      "Catalytic": "No",
      "Maximum BTU's Per Hour": 75000,
      "Higher Heating Value Efficiency (HHV)": 0.733,
      "Lower Heating Value Efficiency (LHV)": 78.4,
      "Steady-State Efficiency": "n/a",
      "Link To Unit": "http://www.regency-fire.com/en/Products/Wood/Wood-Stoves/F2450",
      "Key Features": "Large fire viewing area, with heat radiating ceramic glass\nWood-finished handle\nHeavy duty cast hinges that will never bend or break\nSolid forged steel adjustable cam lock ensures a tight door seal over time\nFront mounted air adjustment\nAir operating safety tool\nHigh performance brick-lined firebox reflects heat\nNon-obtrusive air wash curtain keeps glass clean\nWelded ash lip will never bend or break\nRear heat deflector allowing for closer clearances\nMobile home and alcove approved\nDual-burn design creates longer and more complete burns\nBacked by the industry’s most comprehensive Limited Lifetime Warranty",
      "Product Size": "Medium",
      "Maximum Log Size": "18\"",
      "Burn Time*": "Up to 10 hours",
      "Firebox Capacity": "2.3 cu. ft.",
      "Hopper Size": "n/a",
      "Emissions (g/hr)": "2.3 g/hr",
      "View Area": "161 sq. in.",
      "Exhaust Size": "6\"",
      "Minimum Fireplace Opening (W x H x D)": "n/a",
      "Fireplace Dimensions (W x H x D)": "24\" x 36-5/16\" x 27-3/16\"",
      "Picture Name": "F2450.jpg",
      "Feature Sheet File Name": "F2450 Feature Sheet.pdf",
      "Description": "The Regency Classic Medium Wood Stove provides the perfect amount of heat for most spaces. Load wood in this stove front to back or side to side for the optimum convenience. Backed by our Limited Lifetime Warranty, we are confident that the quality workmanship, finest materials and durable construction of all Regency products, will serve your family for years to come.",
      "Teaser": "The F2450 is a Medium non-catalytic wood stove, comes with your choice of pedestal or legs and it is available in black or with nickel accents.",
      "Additional Picture Name #1": "F2450-B.jpg",
      "Additional Picture Name #2": "F2450-C.jpg",
      "Pricing Reference Name": "001-946"
    }
  ],
  "Company Pricing": [
    {
      "Part Num": "001-915",
      "Part Description": "Gravity Air Kit Z2510/FP90/CF780",
      "Prod Group": "08-WOOD",
      "MSPR USD": 975
    },
    {
      "Part Num": "001-946",
      "Part Description": "Adaptor Air Cool Chimney Sec FTF8",
      "Prod Group": "08-WOOD",
      "MSPR USD": 76
    }
  ]
}

const pricing = new Map(products['Company Pricing'].map(o => [o['Part Num'], o]))

const result = products['Product Info'].map(o => ({ ...o, ...pricing.get(o['Pricing Reference Name']), }))

console.log(result)
👤Nick

Leave a comment