Home > front end >  how to implement span tag in an array to html
how to implement span tag in an array to html

Time:03-17

let array= ["<span style="font-weight:900">everthing</span> is perfect", "Look for opportunities in <span style="font-weight:900">every</span>change"]

array.map((arr) => {
          return (
              <div>
                {arr}
              </div>
          );
        })

Desired output:

everthing is perfect Look for opportunities in every change

My output:

<span style="font-weight:900">everthing</span> is perfect 
Look for opportunities in <span style="font-weight:900">every</span>change

please help me.

CodePudding user response:

You must install a package for that.

yarn add react-html-parser
npm install react-html-parser

then.

import ReactHtmlParser from 'react-html-parser'; 
<div> { array.map((arr)=>(
    {ReactHtmlParser (arr)}
)) } </div>
  • Related