2

I would like to import these data file values in an array. so times[0] would be 23,8 etc...

Example data file web.txt (temperature values in C°):

23,8
23,2
22,8
22,0
... etc

The code below is what i have thusfar reading the web.txt file and displaying the values in a browser.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>load demo</title>
  <style>
  body {
    font-size: 16px;
    font-family: Arial;
  }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<p id="myid"></p>
<script>
var times = [];

 $.get('web.txt', function(data) {
        //var fileDom = $(data);

        var lines = data.split("\n");
        $.each(lines, function(n, elem) {
            $('#myid').append('<div>' + elem + '</div>');
        });
    });


</script>
</html>
3
  • you already have the array in lines. Why do you need 2 arrays? Commented Oct 30, 2014 at 15:04
  • i didnt realise that lines was also an array Commented Oct 30, 2014 at 15:08
  • well that doesn't really make sense or you wouldn't have created an each loop of lines Commented Oct 30, 2014 at 15:36

1 Answer 1

1

That works.

Just rename

var lines = data.split("\n");
$.each(lines, function(n, elem) ...

to

times = data.split("\n");
$.each(times, function(n, elem) ...
Sign up to request clarification or add additional context in comments.

1 Comment

var times should times, because it has previously been declared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.