JSFiddle - React, Tailwind, and code Playground
by Serge Zahharenko
HTML
<pre id="log"></pre>
JavaScript
var jsn = [
{"i":1, "t":"free"},
{"i":2, "t":"sales"},
{"i":3, "t":"free"},
{"i":4, "t":"free"},
{"i":5, "t":"free"},
{"i":6, "t":"sales"},
{"i":13,"t":"free"},
{"i":14,"t":"free"},
{"i":15,"t":"sales"},
{"i":16,"t":"free"},
{"i":17,"t":"sales"},
{"i":21,"t":"free"},
{"i":22,"t":"free"},
{"i":23,"t":"sales"},
{"i":26,"t":"free"},
{"i":27,"t":"sales"},
{"i":36,"t":"free"},
{"i":37,"t":"free"},
{"i":38,"t":"sales"}
]
for (var i = 0; i < jsn.length; i++) {
if (jsn[i].t == 'sales') {
var next = jsn[i+1] || false;
if (next) {
if (next.i % 2 == jsn[i].i % 2) jsn.splice(i+1, 0, 'test');
}
}
}
$('#log').html(JSON.stringify(jsn, null, 4));