How to append an object to specific index in JSON file with fs libarary?

  arrays, file, fs, javascript, json

Is there a way to append an object to a specific index in a file ?
I have a data.json file wich looks something like that :
(A that inside has an array that holds objects)

[
{
id,
name, 
.....
} , 
{
id,
name, 
.....
},

]

whenever I try to append an object to this file it adds it after the closing tag of the array (I mean outside of the array but I would like to append it into the array , How can I do it ?

Source: Ask Javascript Questions

LEAVE A COMMENT