¿Cómo puedo limitar for-in a 5 bucles incluso si hay más propiedades en el objeto?
for(property in object){ //do this stuff for the first 5 properties }Sin contadores:
Object.keys(object).slice(0,4).map((property) => { // do something with property })Podrías usar un contador. Algo como esto:
let counter = 0; for(property in object) { if (counter >= 5){ break; } counter++; }Puedes usar un break;
Como esto
let props = 0; for(property in object){ //do this stuff for the first 5 properties props++; if (props > 4) break; }