Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
Reading a Seriers of Numbers from a txt file into an Array with JSON but every digit is now seperated

So I've used JSON to get a Series of Numbers from .txt into an array in JavaScript but once i try to log them with something like console.log(testbodysnake[0][0]) i just get the bracket [ instead of the following number.

This is what it looks like in the .txt file
[(400, 160)]
[(400, 140)]
[(400, 120)]
[(400, 100)]
The output is logged like this 
console.log(testbodysnake[0][0],testbodysnake[0][1], testbodysnake[0][2], testbodysnake[0][3], testbodysnake[0][4], testbodysnake[0][5], testbodysnake[0][6], testbodysnake[0][7], testbodysnake[0][8], testbodysnake[0][9], testbodysnake[0][10], testbodysnake[0][11])
[ ( 4 0 0 ,   1 6 0 ) ]
Getting the values from the .txt file

<?php
$handle = fopen ("testbodysnake.txt", "r");
$testbodysnake = [];

while ( !feof($handle))
{
  $testbodysnake[] = fgets($handle);

}

fclose($handle);
print_r($testbodysnake);
?>
Getting the Values into the array

var testbodysnake = []; 
    var testbodysnake = <?php echo json_encode($testbodysnake); ?>; 

Does anybody know how i can easily fix this issue and get the array to read the numbers as a whole? Any help would be appreciated

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda