Associative Arrays

The backbone of JS

by db_dev

HTML

<h4>
    Index Array
</h4>
<code id="arrays" class="code-box">
	<ul>
	</ul>
</code>

SCSS

body,
html {
    background-color: #20272f;
    box-sizing: border-box;
    height: 90%;
    font-family: sans-serif;
    color: #dbd7f2;
}

.code-box {
    background-color: #2d4866;
    border: solid 1px #839cad;
    border-radius: 5px;
    padding: 12px;
    width: 95%;
    display: block;
    height: 100%;
}

JavaScript

var codeBox = $("#arrays ul");

//codeBox.text();

var items = new Array(
    123456,
    789012,
    345678,
    901234
);

for (index = 0; index < items.length; index++) {
    codeBox.append('<li>' + index + ' : ' + items[index] + '</li>');
}

var aaItems = new Array();

aaItems['foo'] = 123456;
aaItems['bar'] = 789012;
aaItems['baz'] = 345678;
aaItems['bat'] = 901234;
for (var index in aaItems) {
    codeBox.append('<li>' + index + ' : ' + aaItems[index] + '</li>');
}