This resolves unless your.txt file is too chaotic.
var numsList = [];
$.ajax( 'arquivo.txt', {
dataType: 'text',
success: function(response){
//response é o conteudo do arquivo.txt
var lines = response.split('\n'); //quebra o arquivo em linhas,
for(var i in lines){
var row = lines[i];
var nums = row.split(','); //quebra a linha em valores separdos por virgula
for(var j in nums){
var num = parseInt(nums[j]); //converte o valor para int
if( !isNaN(num) ) //basicamente verifica se é um numero
numsList.push(num); //adiciona o item no array
}
}
console.log(numsList);
}
});
I tested the code in a txt file with the following content
1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21, 22, 23, 24, 25,26, 27, 28, 29, 30
But what is the content of the txt file?
– Jéf Bueno
First Voce needs to load the txt file, then Voce uses ajax, from ai Voce will already have the contents of txt as string, then just manipulate it. As there is no more information it is difficult to give examples. if you can put content or txt snippet it helps enough
– Neuber Oliveira
jbueno, only numbers.
– Caraujo
@Neuberoliveira, the contents are only numbers, can be 1 in each line or separated by comma.
– Caraujo