JSFiddle - React, Tailwind, and code Playground
by konglie
HTML
<h1 id='res'>
</h1>
JavaScript
var json = [{"1":3},{"2":2},{"5":6},{"12":1}];
var cariID = 5;
function findIndex(id) {
var item;
for (var index in json) {
item = json[index];
if(Object.keys(item)[0] == id){
return index;
}
}
return -1;
}
document.getElementById('res').innerHTML = cariID + ' ada di index ' + findIndex(cariID);