Split a string of HTML into an array by particular tags

后端 未结 4 779
遇见更好的自我
遇见更好的自我 2021-01-05 00:41

Given this HTML as a string \"html\", how can I split it into an array where each header marks the start of an element?

Begin with this:

4条回答
  •  青春惊慌失措
    2021-01-05 01:12

    Hi I used this function to convert html String Dom in array

      static getArrayTagsHtmlString(str){
        let htmlSplit = str.split(">")
        let arrayElements = []
        let nodeElement =""
        htmlSplit.forEach((element)=>{  
          if (element.includes("<")) {
            nodeElement = element+">"   
           }else{
             nodeElement = element
            }
            arrayElements.push(nodeElement)
        })
        return arrayElements
      }
    

    Happy code

提交回复
热议问题