I have two object arrays obj1 and obj2, how to get the array that matches key color-size of obj1 and model of obj2
Below function works, is there alternative way to do
getArrayByModel(obj1,obj2){
return obj2.filter(o1 => obj1.some(o2 => o1.model=== (o2.color+ "-" + o2.size)));
}
console.log(this.getArrayByModel(obj1,obj2));
var obj1 = [
{ id:1, color:"blue",size:"m"}
]
var obj2 = [
{ idx:1, model:"blue-m", store:"111" },
{ idx:2, model:"blue-xs", store: "123"},
{ idx:3, model:"blue-m", store: "345"},
]
Expected Output
[
{ idx:1, model:"blue-m", store:"111" },
{ idx:3, model:"blue-m", store: "345"}
]