Skip to content

Instantly share code, notes, and snippets.

@green3g
Last active March 1, 2022 21:11
Show Gist options
  • Save green3g/00d5563e4392e8c2bf752c679367fd4f to your computer and use it in GitHub Desktop.
Save green3g/00d5563e4392e8c2bf752c679367fd4f to your computer and use it in GitHub Desktop.
object to array
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/default.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon-variables.min.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js"></script>
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to "main" (data-main attribute on script)
which is your src/main.js.
-->
<body class="p-20">
<p>Input Data: </p>
<pre><code id="data" class="language-json" style="width: 100%;"></code></pre>
<p>Expected Result:</p>
<pre><code id="expected" class="language-json" style="width: 100%;"></code></pre>
<p>Current Result:</p>
<pre><code id="result" class="language-json" style="width: 100%;"></code></pre>
<script src="/dist/entry-bundle.js" data-main="main"></script>
<script>
const expected = [
{key: 'name', value: 'john'},
{key: 'phone', value: '111-222-3333'},
];
const data = {
name: 'john',
phone: '111-222-3333'
};
document.querySelector('#expected').innerHTML = JSON.stringify(expected, null, 4);
document.querySelector('#result').innerHTML = JSON.stringify(objectToArray(data), null, 4);
document.querySelector('#data').innerHTML = JSON.stringify(data, null, 4);
hljs.highlightAll();
</script>
</body>
</html>
{
"dependencies": {}
}
// TODO: implement this function
function objectToArray(obj){
// try to make the "current result" match the "expected result"
return [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment