0
I have the following variable:
var prodadicional = $(this).attr('data-adicionais');
It returns two string-like values that are: Burger and Bacon.
Like I do to put them inside a array
?
I tried to pass inside the array
and rely on length
but only returns the value 1, having two values.
var dadosarrayAdicional = [prodadicional];
var teste = prodadicional.length;
Does it no longer return you in an array? When you give one
alert(prodadicional)
orconsole.log(prodadicional)
he returns to you what?– Leonardo Pessoa
If I put var test = dadosarrayAdicional.length; it returns the value 1. But it has 2 values.
– Felipe Michael da Fonseca
Give a console.log(additional output ) and provide the result please.
– Bruno Rigolon
If I by prodadicional.length it returns (16)
– Felipe Michael da Fonseca
You are placing an array within another array, so the Count of the first array is actually 1, but within that array has 2 elements..
– leofontes
tried using JSON.stringify()?
– adventistaam
The question is not very clear Felipe, try to put some verifiable example and/ or clarify better the inputs and outputs - as is the most you will get are guesses.
– BrTkCa
If you receive a string, you have to transfer it in array before, if your string is even "Burger and Bacon", receive as var prodadicional = $(this). attr('additional date'). split("and");
– Felipe Duarte
If I give a console.log(additional prod) it returns the value in string. Burger and Bacon. I want him to put these variable values in an array and count the number of items right after to be able to do a for and list the data in each LI. Type Burger would stand on one LI and Bacon on another. Only if I give a dataArrayAdicional.length it returns 1.
– Felipe Michael da Fonseca
It returns a string
"Hambúrguer e Bacon"
or[{"lanche":"Hambúrguer","lanche":"Bacon"}]
or how?– adventistaam
String Hambúrger and Bacon.
– Felipe Michael da Fonseca
Then do as @Felipeduarte said: separating the string with split ai will become array, from now on you can do what you want
– adventistaam