Cannot find function includes error message

Hello - I have this script that I have used in the past. Now when I try to use it it is throwing an error ( cannot find function includes ). I also tried ‘indexOf’. Does anyone know why this will not work now? All this is trying to do is look at a field set to float and if it has a negative sign in front, replace with ().

results.each(function(index) {
var field, result = “”, newField;

field = record.tables["detail"][index].fields["Reduction"];
if (field !== "" && field.includes("-")) {
	result += "(" + "$" + field.replace("-", "").trim() + ")" ; 
	this.html(result);	
}else{
	result += "$" + field;
}

this.html(result);

});

Thank You

Try casting the 'field" variable to a string first:

if (field !== “” && field.toString().includes(“-”)) {

1 Like

I would go one step further and check if the field variable is not null/undefined/empty (which is different than only checking if it contains an empty string value):

if (field && field.toString().includes("-"))
1 Like

Thank you!! They both work great