For semantic brevity, would you not want to pull the filter func outside the for..of loop? Also utilizing const seems more ideal.
filter
for..of
const
function xml2json(srcDOM) { const children = [...srcDOM.children]; if (!children.length) return srcDOM.innerHTML const jsonResult = Object.create(null), childIsArray = (x, y) => x.filter(z => z.nodeName === y.nodeName).length > 1; for (const child of children) { if (!childIsArray(children, child)) jsonResult[child.nodeName] = xml2json(child); else { if (jsonResult[child.nodeName] !== undefined) jsonResult[child.nodeName].push(xml2json(child)); else jsonResult[child.nodeName] = [xml2json(child)]; } } return jsonResult; }
I am researching how others approached this scenario due to a similar surprise on my current project. Nice approach!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For semantic brevity, would you not want to pull the
filter
func outside thefor..of
loop? Also utilizingconst
seems more ideal.I am researching how others approached this scenario due to a similar surprise on my current project. Nice approach!