document.addEventListener('DOMContentLoaded', () => { launch(); }); const launch = () => { viewArray('joana'); }; viewArray = (name) => { const arrayName = ['pere', 'marti', 'joana', 'ricard', 'ramon', 'judit']; let key = 0; const arrayView = setInterval(() => { if (key === arrayName.length) { clearInterval(arrayView); console.log(`No s'ha trobat l'usuari`); } else { console.log(arrayName[key]); if (arrayName[key] === name) { clearInterval(arrayView); console.log(`S'ha trobat l'usuari: ${name}`); } key++; } }, 3000); };