1
I have a constant doubt about the Length
and the noose for
to measure an array or a string.
Doubt 1:
When we use that code:
const numero ="teste";
const medir = numero.length;
console.log(medir)
It returns the value 5. But if we use as an array:
const numero = ["Saab", "Volvo", "BMW"];
const medir = numero.length;
console.log(medir)
It returns 3. Why ?
Doubt 2:
How does it work inside For? I have the code:
const separador = " - ";
function filtro(funcao, numeros2) {
let stringNova = '';
for (let i = 0; i < numeros2.length; i++) {
stringNova += numeros2[i] + (funcao)
}
return stringNova
}
console.log(filtro(separador, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
for (let i = 0; i < numero.length; i++)
How exactly does this piece of code work? People explain it to me but explain it to me in a technical way and I’m new and it’s not so clear to me.
So this code means that:
i(0)
is less thannumero.length(5 )
; will increase untili
is equal tonumero
?– Jota
That while
i
is a minor.– Laerte