Error when checking if string contains “->”

I am looking to go through the two strings seen below and check if it contains “->” and if that it True, I would like to check that the text after it does not contain any text, if both true, it should run through the code. So in the first NTE, it should go through just fine, while when NTE is “TEST” it should stop and not modify anything, but instead its throwing an error.

NTE = “Exceptions:->1/1/22”
NTE = “TEST”

I am using the below if to check if it contains “->” but its not working properly

 /* Single input message case */
 // Create the output message 
 var next = output.append(input[0]);
 var lib    = require('DateHelper');

 var ODS;
 var NTEcnt;
 var ODScnt;
 var NTE;
 var result;
 var date1;
 var longDate;
 var quantity;

 NTEcnt = next.getRepeatCount('CommonOrders[0]/DietaryOrder/NTE');
 //log.debug("NTEcnt:"+ NTEcnt); //gives count of NTE segments

 ODScnt = next.getRepeatCount('CommonOrders[0]/DietaryOrder/ODS');
 //log.debug("ODScnt:"+ ODScnt);  //gives count of ODS segments

 for(var i = 0; i < NTEcnt; i++) {
        NTE = next.getField('CommonOrders[0]/DietaryOrder/NTE['+ i +']/Comment[0]');
        log.debug("NTE: "+ NTE);
    
        result = NTE.split("->")[0] + "->"; // split "splits" the string into an array based on the delimiter "->"
        //log.debug("Before >: "+ result);
        
        
        function includesMatch(lookupValue, testString){
            var re = new RegExp(lookupValue, 'i'); //Here the 'i' means that we are doing a case insensitive match
            return testString.match(re) !== null
        }

        //if(!includesMatch(NTE, "->")){
            if(NTE.search("->") != -1){         
                
                var contains = true;
                log.debug("it contains ->");
                date1 = NTE.split("->")[1]; // splits the string into an array based on the delimiter "->"
                log.debug("After >: "+ date1);

            } else {
                var contains = false;
                log.debug("it does not contain ->");
            }
    
if(contains = true){
if(date1.length>=6){
    var dateTimeSec = lib.FormatDate(date1, 'MM/dd/yy','MM/dd/yyyy');
    var dateTimeORC = lib.FormatDate(date1, 'MM/dd/yy','yyyyMMdd'+"000000");
    var whatDate= lib.isDate(dateTimeSec);
    log.debug('My date = ' + dateTimeSec);
    log.debug('My date ORC long = ' + dateTimeORC);
    log.debug('My date = ' + whatDate);
} else {
    quantity = date1;
}
} else {

}



if(contains = true){    
    if(result == 'Packet:->' || result == 'Serving:->' || result == 'Can/Carton/Bottle:->'){
        for(var j = 0; j < ODScnt; j++){
        ODS = next.getField('CommonOrders[0]/DietaryOrder/ODS['+ j +']/DietSupplementOrPreferenceCode[0]/Identifier');
            if(ODS == '500DIET70' || ODS == '500DIET71' || ODS == '500DIET72' ||  ODS == '500DIET73' || ODS == '500DIET76' ||  ODS == '500DIET77'){
                
                    next.setField('CommonOrders[0]/ORC/QuantityTiming[0]/Quantity/Quantity','1');
                    next.setField('CommonOrders[0]/ORC/QuantityTiming[0]/Quantity/Quantity',quantity); //rewrite ORC_7.1
                    
                    log.debug("Quantity of NTE :"+ quantity);
                    
                    next.setField('CommonOrders[0]/ORC/QuantityTiming[0]/StartDateTime',dateTimeORC); //rewrite ORC_7.4
                    log.debug("Longer Date : "+ dateTimeORC);
            } //end if
        }  //end for
    } //end if
                        

} else {

}


}   

2022-01-16 03:38:48,798 DEBUG [ ] NTE: TEST
2022-01-16 03:38:48,798 DEBUG [ ] it does not contain ->

enter image description here