Replace in the javascript array

1

Good afternoon, friends I have a problem here in javascript. I have an array, but with each index it is adding a double quotation mark, and I want to remove them from there. My code looks like this:

    dados = new Array();
       $.get(url, function(response){
       for(i in response.content) {
           horario = parseInt(response.content[i].Horario);
           tempo = parseInt(response.content[i].Tempo);
           dados[i]= "["+ horario +", "+ tempo  + "]";
           dados[i] = dados[i].replace(' " ', ' ');
       }

       console.log(dados);

   });

And my return is like this

  

And it would have to look like this:

  

[[0, 54], [0.65], [10, 60]]

Does anyone know if why replace is not working?

EDIT

I forgot to mention the important part, I'm going to use this array for a chart and the data model it reads is like this:

data: [ [0, 54], [5, 65], [10, 60] ]

So I already concatenated there in it the open "keys" in each of the indices

    
asked by anonymous 08.03.2016 / 15:44

3 answers

1

Well let's convert the comment to practice:

  

Luan of the way you are doing this by creating a one-dimensional array of String, and what you want is a two-dimensional array of Int, so you have to assign the array with time, time, p>

dados = new Array();
    $.get(url, function(response){
    for(i in response.content) {
            horario = parseInt(response.content[i].Horario);
            tempo = parseInt(response.content[i].Tempo);
            dados[i] = new Array();
            dados[i].push(horario);
            dados[i].push(tempo);
    }
    console.log(dados);
});
    
08.03.2016 / 15:59
1

All the answers have solved your problem, but they did not answer what you asked, so here is the answer to your question, just for future cases (what they answered is correct)

Your replace did not work because of a syntax error.

the correct form would be

data [i] = data [i] .replace (/ "/, '');

The value to be replaced has to be surrounded by slashes, and if you want to remove something need to put an empty string after the comma, not a string with a space inside (otherwise it will have a space before and one after each key).

    
24.04.2018 / 23:43
0

The question is, how much do you replace '' 'by' 'still has a string array? Where each record contains a set of [number, number]. of the console to present an array of string will always be ["value1", "value2"] and etc ...

This gives the impression that replace is not working when it actually is. But as I said it is still a string array. If you put a console showing only the replace you will see that it is right.

To summarize use eval to transform the array of string into array of numbers see:

var dados = [];
for(i in [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) {
	dados[i]= "["+ i +", "+ 5  + "]";
}

console.log(dados);

for(i in [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) {
	dados[i] = eval(dados[i]);
}

console.log(dados);
    
09.03.2016 / 01:21