I've been doing research on testing if a value exists in an array, and keep getting matches for indexOf('textvalue').
But, my 'textvalue' will be a substring, and therefore won't pull a match. This is because I'm passing the field name to the method, and just need to delete the "Door: Front Left;" text by matching the array item on "Door". Does anyone know how I can accomplish this?
Here's the example code I'm working on:
(spnSelectedDisclosures will have a list of selected fields, and this is the code to remove the previous field selection from the text, which is semi-colon delimited.)
var currentText = $("#spnSelectedDisclosures").text();
var existingArr = currentText.split(";")
for (i=0;i < existingArr.length;i++) {
var indexItem = " " + existingArr[i].toString(); // why is this still an object, instead of a string? Adding a space to it was a desperate try to make indexItem a string variable.
if (indexItem.contains(substringText)) { // offending line, saying the object has no method 'contains'
alert("there's been a match at: " + i);
textToRemoveIndex = i;
break;
}
}
var textToRemove = existingArr[textToRemoveIndex];
var newText = currentText.replace(textToRemove,"");
$("#spnSelectedDisclosures").text(newText);