Skip to content

Instantly share code, notes, and snippets.

@hadrienl
Last active September 2, 2016 13:04
Show Gist options
  • Save hadrienl/15cf3ad5b21feec744481b637fca4145 to your computer and use it in GitHub Desktop.
Save hadrienl/15cf3ad5b21feec744481b637fca4145 to your computer and use it in GitHub Desktop.
replaceArrays
<!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>
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>`
/* todo: add styles */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment