Last active
September 28, 2016 13:19
-
-
Save ktrysmt/699f0a056780283b3f8d63e6c4a36a23 to your computer and use it in GitHub Desktop.
Convert from a DOM Node included childNodes nested to a nested array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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