SOURCE

function getHtml(obj = {}) {
  var content = obj.content || ''
  var textList = obj.textList || {}

  var reg = new RegExp(`(${textList.join('|')})`, "g")
  content = content.replace(reg, (...args) => {
    var index = textList.findIndex(item => item == args[0]) 
    var color = 'blue'
    var fontSize = '20'
    if (index == 2) {
      color = 'red'
      fontSize = '18'
    }
    return `<span style="color:${color};font-size:${fontSize}px;">${args[0]}</span>`
  })

  return content
}

var html = getHtml({content: 'ge我是segemtfault', textList: ['我是', 'ge', 'fault']})
console.log(html)
document.write(html)
console 命令行工具 X clear

                    
>
console