Last active
September 2, 2016 13:04
-
-
Save hadrienl/15cf3ad5b21feec744481b637fca4145 to your computer and use it in GitHub Desktop.
replaceArrays
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>GistRun</title> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<h1>Hello world!</h1> | |
<script src="script.js"></script> | |
</body> | |
</html> |
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
const content = { | |
foo: 'bar', | |
bar: { | |
coin: { | |
lol: ['a', 'b', 'c', 'd'], | |
pwet: { | |
gra: ['1','2','3'] | |
} | |
} | |
} | |
} | |
function replaceArrays(parent) { | |
for (let k in parent) { | |
const node = parent[k]; | |
if (Array.isArray(node)) { | |
parent[k] = node.join(''); | |
continue; | |
} | |
if (typeof node === 'object') { | |
replaceArrays(node); | |
continue; | |
} | |
} | |
} | |
replaceArrays(content); | |
document.body.innerHTML = `<pre>${JSON.stringify(content, null, ' ')}</pre>` |
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
/* todo: add styles */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment