-1

Welcome everyone!

My question is that, when I push the item object into the imported orderJSON , the data appear on the console, how can I add this object into the JSON file?

enter image description hereenter image description here

I tried the file reading and writing, but I didn't achieve any success.

Thanks for your helps!

  • Please read [ask] in particular the parts about providing a [mcve] (You claim "I tried the file reading and writing" but you haven't shown us that), providing a clear description of the problem ("I didn't achieve any success" [isn't useful](https://idownvotedbecau.se/itsnotworking/)) and **not** posting **text** in the form of **pictures**! – Quentin Oct 28 '22 at 08:24
  • Does this answer your question? [Add new attribute (element) to JSON object using JavaScript](https://stackoverflow.com/questions/736590/add-new-attribute-element-to-json-object-using-javascript) – SMAKSS Oct 28 '22 at 08:30
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 28 '22 at 10:33

1 Answers1

0

you need some apis of the node.js to manipulate the json file. for example:

const fs = require('fs');
fs.writeFile('your json file path', 'your json content', (err) => {
    if (err) {
        console.log(err)
    }
}

But, I don't think so that is a good idea for you. You can use localstorage api, that is easier and more suitable to reslove this scene for you.