-1

I have this challenge:

var tx =  "<p>This is a sample picture. <img src="" alt="Sample picture"> This picture is the best for the advertising...</p> ";

How do I format this variable to remove the img tag and have a result:

    tx = "<p>This is a sample picture. This picture is the best for the advertising...</p> ";
trincot
  • 317,000
  • 35
  • 244
  • 286
Olu Teax
  • 149
  • 1
  • 5

1 Answers1

2

You can do it using Regular Expression. Try this:

var tx =  "<p>This is a sample picture. <img src='' alt='Sample picture'> This picture is the best for the advertising...</p> ";

const res = tx.replace(/<img[^>]+>/, '');

console.log(res);
Sajeeb Ahamed
  • 6,070
  • 2
  • 21
  • 30