D
D
da_da_ya_neudachnik2022-02-09 17:55:39
JavaScript
da_da_ya_neudachnik, 2022-02-09 17:55:39

How to create a JSON entry?

Is it possible to make it so that after entering the command a new entry is created in the JSON file?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stas Ostrovsky, 2022-02-09
@da_da_ya_neudachnik

Oh sure.
for example:
let test = []; //object, mutable.
test.push({ //adding a new array.
//native code
});
console.log(test) //output.

D
defriz, 2022-02-09
@defriz

Let's create a json file in the folder with the code and connect it to it. in json file [].
after that we will autosave this json every 1.5 seconds. connect fs module

const tasks = require('./tasks.json'); // массив
const fs = require('fs'); // модуль fs
setInterval(async() => {
fs.writeFileSync("./tasks.json", JSON.stringify(tasks, null, "\t"));
}, 1500); // "автосохранение" tasks.json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question