Replace numbers in String Javascript
const dataString = JSON.stringify(dataArray);
const regex = /<span.*?>|<\/span>/gm;
const newData = dataString.replace(regex,'');
JSON.parse(newData);
This should do it.
You can iterate the array and replace the content inner the arrow. Like that:
arr = [
{
"name": "testOne",
"tag": "<span id=my-test-1>Test One</span>"
},
{
"name": "testTwo",
"tag": "Test Two"
},
{
"name": "testThree",
"tag": "Test Three"
},
{
"name": "testFour",
"tag": "<span id=my-test-2>Test Four</span>"
}
]
n = arr.map(a => {
a.tag = a.tag.replace(/>.*</g, "><");
return a;
})
console.log(n)
you can do it using regex
const dataToString = JSON.stringify(dataArray);
const regex = /"<span([^]*)</span>"/gm;
const newData = dataString.replace(regex,"");
JSON.parse(newData);
when I put this code ([^]*)
between the span tags it matches any character