0
I have this variable: 10 + 20 + 30 + 40 + 50 = 150
.
I want to know how I can use the implode()
Javascript to remove anything that is in front of each number, can be any sign or special characters, this string can also have several sizes.
Desired result:
var numero = 10 + 20 + 30 + 40 + 50 = 150;
var 10 = 10
var 20 = 20
var 30 = 30
var 40 = 40
var 50 = 50
var igual = 150
My code:
var valor = "10+20+30+40+50=150";
var separar = valor.split('+');//Nesse caso fica limitado ao sinal de adição
alert(adicao);
the
implode
only transforms an array into a string separated by distinct characters, and these characters do not go together with the value saved. To remove signals, a regular expression should be used, in the case of the transformed array, using a loop.– William Aparecido Brandino
Remembering q you can’t create variables starting with numbers.
– Laerte
Can be ( n_10 ) ( n_20 ) and so on
– abduzeedo
valor.replace('=','+').split('+')
this way you will have an array with all values in the same order that are in your variable. This helps?– Pedro Camara Junior
So it can be any sign or any special characters, it can be ( 10@10) / (10/10) / (10*10 ) or any other arithmetic sign or special character.
– abduzeedo
What are you going to do with these values? This is the most important, this is what defines what the output format needs to be.
– bfavaretto
or even, you can use a regex in the split, so:
valor.split(/\D/)
– Pedro Camara Junior