Skip to content

Instantly share code, notes, and snippets.

@ktrysmt
Last active September 28, 2016 13:19
Show Gist options
  • Save ktrysmt/699f0a056780283b3f8d63e6c4a36a23 to your computer and use it in GitHub Desktop.
Save ktrysmt/699f0a056780283b3f8d63e6c4a36a23 to your computer and use it in GitHub Desktop.
Convert from a DOM Node included childNodes nested to a nested array.
var convert = (a) => {
var r = []
if (a.firstChild === null) {
r.push(a)
}
else if (a.childNodes.length > 0) {
var c = a.childNodes
Array.from(c).forEach(function (v) {
if (v.firstChild === null) {
r.push(v)
}
else {
var x = convert.apply(this, [v])
r.push.apply(r, [x])
}
})
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment