script.js
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('./data.json', 'utf8'));
let num = data.length;
let arr = "[\n";
let que_name = "sym";
let ans_name = "name";
let file_name = "copy_data";
data.forEach((value, index) => {
let txt = "";
txt += " { "
txt += `"que" : "${value[que_name]}"`
txt += `, "ans" : "${value[ans_name]}"`
if(num == value["no"]){
txt += " }\n"
} else {
txt += " },\n"
}
arr += txt;
})
arr += "]"
fs.writeFile(`./${file_name}.json`, arr, (err) => {});
data.json
[
{ "que" : "H", "ans" : "水素" },
{ "que" : "He", "ans" : "ヘリウム" },
{ "que" : "Li", "ans" : "リチウム" },
{ "que" : "Be", "ans" : "ベリリウム" }
]