I currently have two arrays named available and selected, each containing certain values. I also have another array called finalAvailable where I want to include all items from the available array except those that are already present in the selected array. This is illustrated in the example below:
var available = ["A", "B", "C", "D", "E"];
var selected = ["B", "C"];
Therefore, the contents of the finalAvailable array should be as follows:
var finalAvailable = ["A", "D", "E"];
I have successfully implemented a code to achieve this functionality. However, my team lead advised me to explore potential options within Lodash to accomplish the same task. Unfortunately, after conducting some research, I couldn't find any specific function in Lodash that directly addresses this requirement. I'm unsure if I may have overlooked something.
If anyone is aware of a similar feature available in Lodash, kindly share that information with me.
The current code I am using for this operation is provided below:
var available = ["A", "B", "C", "D", "E"];
var selected = ["B", "C"];
var finalAvailable = [];
for (var i = 0; i < available.length; i++) {
var flag = true;
for (var j = 0; j < selected.length; j++) {
if (available[i] == selected[j]) {
flag = false;
}
}
if (flag) {
finalAvailable.push(available[i])
}
}