0
The purpose of the code is to make each value of the arrays (x, y, z) have a "$"
before, then before it was "exemplo"
and turns "$exemplo"
.
I tried to do it this way, but the output comes out like "undefined"
. If it is possible to say where I was wrong and how the code (fixed) works I thank you very much.
This code is a problem that I can use a lot in the future.
function print (value)
{
// pega o tamanho do array;
var all = value.length;
// repete a função de colocar "$" vezes a quantidade de elementos do array
for (i=0; i >= all; i++)
{
var novo = value[i];
var paran = novo.length;
// coloca o "$" no termo atual do array
for (ii = 0; ii>= paran; ii++)
{
var uju = novo.substr(0, -paran)+"$"+novo.substr(-paran);
var name = "";
//cria uma string para juntar todos os valores do array
name = name + uju;
}
}
// output teste do código
console.log(name);
}
var x = ["hehe", "hoho", "haha", "hihi", "huhu"];
var y = ["this", "is", "awesome"];
var z = ["lorem", "ipsum", "dolor", "sit", "amet", ",", "consectetur", "adipiscing", "elit"];
//print(x);
/* var lop = "hehe";
var resultado = lop.substr(0, -4)+"$"+lop.substr(-4);
console.log(resultado); */
print(x);
Have you tried the method
map
of arrays (Array.prototype.map
)? :-)– Luiz Felipe
I don’t understand how the map works @Luizfelipe .
– user216621
Two things, without going into detail: 1) you are complicating much more than necessary and 2) your loops never perform because the conditions you put in are never met
– bfavaretto
@bfavaretto
for
I would repeat x times until he became equal toparan
.– user216621
The second argument of the for is not the condition to stop, but to continue. You’re doing it backwards. And do not need another go inside to put a prefix nodes values. Neither subst and related
– bfavaretto
@bfavaretto understood what you meant, already fixed.
– user216621