JSFiddle - React, Tailwind, and code Playground

HTML

<div id="range"></div>
<div id="items"></div>
<div>Those last two items should be reversed! If the commented for loop runs, it behaves as expected.</div>

CSS

div {margin-top: 12px}

JavaScript

var colors = d3.scale.category10();
console.log(colors.range());
// Produce a pretty output in addition to console log.
var range = d3.select("#range");
colors.range().forEach(function(item) {
    range.append("span").style("color", item).text(item);
});

//  for (var i = 0; i < 10; i++) {
//    colors(i);
//  }

// Unless the above loop runs, these return the zeroth and
// first items respectively, instead of the first and zeroth.
console.log(colors(1), colors(0));
// Pretty output.
var items = d3.select("#items");
[colors(1), colors(0)].forEach(function(item) {
   items.append("span").style("color", item).text(item);   
});