LoginSignup
1
0

More than 1 year has passed since last update.

saveAsJSON.js

Posted at
function saveAsJSON(data, name=new Date().toLocaleString('sv').replace(' ','T').replaceAll(':','_')+'.json') {
  const a = document.createElement('a')
  a.download = name
  a.href = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], {type: 'application/json'}))
  a.click()
}

JavaScriptのデータを保存する

Usage

saveAsJSON(['pen', 'pineapple', 'apple', 'pen'])

// ファイル名を指定
saveAsJSON(['pen', 'pineapple', 'apple', 'pen'], 'hoge.json')

image.png

1
0
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
0