1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

これ書くだけ!JavaScriptで配列をcsv書き出し

Last updated at Posted at 2020-12-06

用意した配列を「test」という名前だとします。
だとしたらこれを入れるだけでいいです。

var test = ['あああ','いいい','ううう'];

let bom  = new Uint8Array([0xEF, 0xBB, 0xBF]);
let blob = new Blob([bom, test],{type:"text/csv"});
let link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = '作ったファイル.txt';
link.click();

ここのコードを書き換えました。JavaScriptで文字列をファイル出力する方法を現役エンジニアが解説【初心者向け】

補足

途中のtext/csvを以下の物にも書き換えれるようです。(audio/mpeg、image/jpegとか)
でもこのためにnew Blobあたりのコードを書き換える必要があると思います。
mozillaに他の書き出し形式もいっぱい書かれているのでぜひ。

https://developer.mozilla.org/ja/docs/Web/HTTP/Basics_of_HTTP/MIME_types
image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?