I am seeking a solution utilizing underscores, but I am open to a vanilla JS alternative if it proves to be the most effective option.
My goal is to utilize array 2 to modify strings in the objects of array1 that either start with or end with the strings found in array2. The desired result can be seen in the modified array3 below:
array1 = [{key1: "Patty Bakery", key2: stuff}, {key1: "Bob Wine Shack",
key2: mattersNot}, {key1: "Romeo Clothing", key2: things}, {key1:
"StackIt", key2: finished}];
array2 = ["Patty", "Romeo", "Wine Shack"];
array3 = [{key1: "Bakery", key2: stuff}, {key1: "Bob",
key2: mattersNot}, {key1: "Clothing", key2: things}, {key1:
"StackIt", key2: finished}];
Currently, the best I have achieved is removing the entire object from array1 using this code snippet:
array1.filter(function(a){
return!_.some(array2, function(b){
return startsWith(a.key1, b)})})
//I have installed and am using underscore.string
This results in an array3 that resembles:
array3 = [{key1:"StackIt", key2: finished}];