Converting a string which includes HTML tags to an array.

What I want to do

"<div>ab cdef ghi</div><div>zxy12345</div>"
[<div>ab cdef ghi</div>, <div>zxy12345</div>]

Code

const str = `<div>ab cdef ghi</div><div>zxy12345</div>`const tmp = Object.assign(document.createElement('div'),{innerHTML:str})const divs = [...tmp.querySelectorAll('div')].map(x=>x.outerHTML); return divs //=>[<div>ab cdef ghi</div>, <div>zxy12345</div>]
<div>
<div>ab cdef ghi</div>
<div>zxy12345</div>
</div>

Started LinkedIn as well!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Story of a website | Introducing HTML, CSS, JavasScript for beginners

Here is the image of Elon (an imaginary boy) trying to understand how web works.

Writing a bill calendar with Node and Express

JavaScript — Variables, Template Literals, For&While Loops

A concise and powerful state management library — iFlow

Create A Subscription Service with Stripe in NodeJS & Express

What Music Can Teach Us About The Way We Share Code

Let’s React to React

[Action required] Your RSS.app Trial has Expired — Sun Jan 16 2022

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tomoharu Tsutsumi

Tomoharu Tsutsumi

More from Medium

TypeScript vs JavaScript

ES6: Inheritance

Generate TypeScript Declaration Files for JavaScript Files

The JavaScript logo with an arrow pointing towards the TypeScript logo

Conditional (ternary) operator in Javascript