In short, what I need is to replace the characters in a string that are a comma with a comma between two single quotes.
The result it gives me does not include single quotes so far.
This is the JS code:
var Cadena = "23,54,N21,98,BIT";
var input = Cadena.trim();
input.replace(",", "\', \'");
var output = input.slice(0, -1);
console.log(output);
You have two problems, the first is that it
replace
only replaces the first occurrence. The next problem is that itreplace
changes the value but it doesn't change the variable you're using, so you have to assign it again.In summary, what you need would look like this: