Home > Blockchain >  compare names and return the names of ones missing in string - Jquery
compare names and return the names of ones missing in string - Jquery

Time:09-11

I have this question. Imagine I have this

var1 = 'october, november, december' var2 = 'november'

I want to compare each and then having the output of the names that are not found in each vars comparison. In this case I want to output in another var, 'october, december'

Is there any way to return that? All I see is true or false options

Edit: It seems I cannot comment posts. No reputation.But im talking about strings.

CodePudding user response:

Probably you can use something like this.

var input = "jan,feb,mar";
var searchTerm = "feb";

var inputArr = input.split(",");
var output = "";
$.each(inputArr, function(i, v){
    if(v != searchTerm)
        output  = inputArr[i]   ",";
});
  • Related