JSFiddle - React, Tailwind, and code Playground
by James
HTML
<input type="text" id="YourElement" value="bla, ble, string1" />
JavaScript
//Create an array from the CSV list
var myVals = $("#YourElement").val().split(",");
var isDupe = false;
for(var i = 0; i < myVals.length; i++) {
if(myVals[i].indexOf("YourNewValue") != -1) {
isDupe = true;
break;
}
}
//use .push() to append your value to the end of the array
if(!isDupe) {
myVals.push("YourNewValue");
//Invoking .toString() on an array creates a CSV list
$("#YourElement").val(myVals.toString());
}