I am trying to merge together the array1 and array2 by matching on the sku. But if a sku has multiple (like 62617802), I want to keep both value from array1 and array2, like, first sku (62617802) will merge with first sku (62617802) of array2 and so on.
Input Note: If the SKU is duplicate (like twice or thrice or so on) in array1 it would be also same on array2. Also if array1 count is 5 then array2 count also 5.
var array1 = [
{
"sku": "35189424",
"price": 107800,
"isNew": false,
"name": "Product Title A"
},
{
"sku": "62617802", // duplicate
"price": 107800,
"isNew": false,
"name": "Product Title D"
},
{
"sku": "GRP00437",
"price": 107800,
"isNew": false,
"name": "Product Title B"
},
{
"sku": "62617802", // duplicate
"price": 107800,
"isNew": false,
"name": "Product Title D"
},
{
"sku": "35189432",
"price": 107800,
"isNew": false,
"name": "Product Title YZ"
}
];
var array2 = [
{
"sku": "35189424",
"Url": "https://......",
"rating": 2,
"status": 0
},
{
"sku": "62617802", // duplicate
"Url": "https://......",
"rating": 5,
"status": 1
},
{
"sku": "GRP00437",
"Url": "https://......",
"rating": 2,
"status": 1
},
{
"sku": "35189432",
"Url": "https://......",
"rating": 3,
"status": 1
},
{
"sku": "62617802", // duplicate
"Url": "https://......",
"rating": 5,
"status": 1
}
];
var outputArray = [
{
"sku": "35189424",
"price": 107800,
"isNew": false,
"name": "Product Title A",
"Url": "https://......",
"rating": 2,
"status": 0
},
{
"sku": "62617802", // duplicate
"price": 107800,
"isNew": false,
"name": "Product Title D",
"Url": "https://......",
"rating": 5,
"status": 1
},
{
"sku": "GRP00437",
"price": 107800,
"isNew": false,
"name": "Product Title B",
"Url": "https://......",
"rating": 2,
"status": 1
},
{
"sku": "62617802", // duplicate
"price": 107800,
"isNew": false,
"name": "Product Title D",
"Url": "https://......",
"rating": 5,
"status": 1
},
{
"sku": "35189432",
"price": 107800,
"isNew": false,
"name": "Product Title YZ",
"Url": "https://......",
"rating": 3,
"status": 1
}
];