Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
17
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Organization

jQueryでテキストファイルを読み込んで改行コード区切りで配列に保存する方法

データの体としては、XMLやJSONであるべきなんだろうけど、テキストデータに保存するのもまだまだあるので、
こちらもメモメモ。

【test.txt】

1行目のデータ
2行目のデータ
3行目のデータ

【JS】

$(function () {
  $.ajax({
    url:'test.txt',
    success: function(data){
      var data_array = data.split(/\r\n|\r|\n/);  // 改行コードで分割
      var len = data_array.length;

      for (var i = 0; i < len; i++){
        console.log(data_array[i]);
      }
    }
  });
});
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
17
Help us understand the problem. What are the problem?