JSFiddle - React, Tailwind, and code Playground

JavaScript

items = { '417': { a: 23, slot_position: 13 },
  '419': { a: 28, slot_position: 2 },
  '420': { a: 29, slot_position: 12 },
  '421': { a: 29, slot_position: 3 },
  '424': { a: 31, slot_position: 17 },
  '425': { a: 32, slot_position: 7 },
  '428': { a: 35, slot_position: 0 },
  '429': { a: 36, slot_position: 0 },
  '431': { a: 42, slot_position: 0 },
  '432': { a: 40, slot_position: 0 },
  '433': { a: 43, slot_position: 11 },
  '434': { a: 44, slot_position: 0 },
  '435': { a: 45, slot_position: 0 },
  '436': { a: 47, slot_position: 0 },
  '437': { a: 48, slot_position: 15 },
  '438': { a: 48, slot_position: 1 },
  '439': { a: 48, slot_position: 0 },
  '440': { a: 48, slot_position: 14 },
  '441': { a: 43, slot_position: 0 },
  '442': { a: 44, slot_position: 0 },
  '443': { a: 43, slot_position: 8 },
  '444': { a: 37, slot_position: 0 },
  '445': { a: 37, slot_position: 0 },
  '446': { a: 37, slot_position: 0 },
  '447': { a: 37, slot_position: 16 },
  '451': { a: 50, slot_position: 5 },
  '452': { a: 49, slot_position: 6 },
  '453': { a: 39, slot_position: 20 },
  '454': { a: 38, slot_position: 4 },
  '455': { a: 19, slot_position: 19 },
  '456': { a: 49, slot_position: 9 },
  '457': { a: 51, slot_position: 0 } };

inventory_slots = 30;
used_slots = [];
for(a in items){
    if(items[a].slot_position > 0){
       used_slots.push(items[a].slot_position);
    }
}

 

for(i=1; i < inventory_slots; i++){
    if(used_slots[i] != i){
        first_open = used_slots[i];  // Why is it only showing 2, not the first open slot?
        break;
    }
}

console.log(first_open);