Maria-Elena
Maria-Elena

Reputation: 127

I need to take off <p> from data using react

I receive data from database like this :

description:<p>my name is ....</p>

I put this in a table, all I need is to put the text only, how can I remove the <p></p>?

Upvotes: 0

Views: 378

Answers (2)

JSONaLeo
JSONaLeo

Reputation: 416

You can explicitly replace the <p> and </p> tags only using the String.prototype.replace() JS string method, available as .replace(string, replacement) on any string in JavaScript. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)

const description = '<p>my name is ....</p>';
const newDescription = description.replace('<p>', '').replace('</p>','');
console.log(newDescription);

Upvotes: 1

Ghazanfar Khan
Ghazanfar Khan

Reputation: 3718

You can remove your html tags by using regex

const htmlRemoveRegex = /(<([^>]+)>)/gi;
const newString = description.replace(htmlRemoveRegex, '');

Upvotes: 0

Related Questions