I'm assuming that you want the items listed in order of the 'value' property in the array (as you mentioned 'blue' should be before 'green'.
If so, you need to sort the array on the appropriate property before iterating through for the output.
Using this method, you can add more items to the array as needed - just call the sort routine before updating the output...
I have updated your code (and that provided in @mcon's fiddle), and added the sort comparer.
Credit to @Wogan for the simple example of the sort function here: https://stackoverflow.com/a/1129270/4619012
<div id="content1"></div>
<script type="text/javascript">
var listContainer = document.getElementById("content1");
var listElement = document.createElement("ol");
listContainer.appendChild(listElement);
var arr = [
{ color: 'red', value: '#f00' },
{ color: 'green', value: '#0f0' },
{ color: 'blue', value: '#00f' },
{ color: 'cyan', value: '#0ff' },
{ color: 'magenta', value: '#f0f' }
]
function compareValue(a, b) {
if (a.value < b.value)
return -1;
if (a.value > b.value)
return 1;
return 0;
}
arr.sort(compareValue);
for (i = 0; i < arr.length; i++) {
var listItem = document.createElement("li");
listItem.innerHTML = arr[i].color + " " + arr[i].value + "</br>";
listElement.appendChild(listItem);
}
</script>