How to exclude a few words from a string field returned from an api response in ReactJS

im trying to exclude a few words from an api string that was returned. I did research on this and saw that people were using REGEX(regular expressions) for this. I tried to copy what they did, however, with api responses, it adds another level of difficulty to it and is not quite the same.

enter image description here

Is there a way to exclude the "Messari Daily Brief" from the api and include everything else? Im trying to grab everything from that title field but the Messari Daily Text.

I tried store the string like this

const title = this.props.newsItems.title;

Then I tried to do the regex:

const extractedString = '/Messari Daily Brief /'

Thanks for taking the time to read this!

1 thought on “How to exclude a few words from a string field returned from an api response in ReactJS”

  1. you can just iterate through the items and replace that string with empty string.
    your items will have now everything except the title does not contain that string(Messari Daily Brief)

    const items = this.props.newsItems.map(item => 
          ({ ...item, title: item.title.replace('Messari Daily Brief', '') }));
    
    Reply

Leave a Comment