I have a constant question about Length
and loop for
to measure an array or string.
Doubt 1:
When we use this code:
const numero ="teste";
const medir = numero.length;
console.log(medir)
It returns the value 5. But if we use it 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 within 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 snippet work? People explain to me but they explain to me in a technical way and I'm new and it's not so clear to me.