Reputation: 336
I'm currently working on a random bible verse generator. When i make a call to the API, it returns text (verse) wrapped in html elements. seems that it was designed that way. How can I get rid of those html elements, to return just the text? this is the output it returns
Upvotes: 0
Views: 147
Reputation: 9063
Assuming you don't want to render the HTML directly in React, a simple approach would be to use a regex replace:
console.log(data.data.passages[0].content.replace(/<[^>]*>/gm, ""));
Though depending on the potential content of the verses this could give things like excess white space, or fail on esoteric HTML cases.
You could also convert it into an DOM node, then get the text out of it. See this answer.
Upvotes: 2