Usage of .map() and .replace()


I have a function which needs to replace all + with ,. Assume the $(".AdvKeyowrdAND").html returns a+b+c+d. I tried to use map() and replace() but it only converts the first + to ,. Did I need to use something like each()?

var array = $(".AdvKeyowrdAND").map(function() {
    return [$(this).html().replace('+',',').split(",")];


jQuery is not the correct thing to be using for updating the string value. map() creates a new array from an existing one, and replace() is intended to update the DOM, not a string.

Instead, use a regular expression to update the value, like this:

$(".AdvKeyowrdAND").text(function(i, text) {
  return text.replace(/\ /g, ',');

This video can help you solving your question :)
By: admin