Message from JavaScript discussions

December 2020

— 😂

— 

How do I save some user's data in my JS or HTML files? Is it even possible or I need a database language?

— Depends what data

— Is it private?

— No

— An example: the user will have to type in a fruit name and the fruit's calories. I want it to be saved in my file, so when someone else calls that same fruit it should show the calories added by the previous user

Message permanent page

— So is there a way to save the added fruit & calories in my JS array & object?

— What do you mean with "save"? temporarily? permanently? From the front-end alone you cannot "save" files or to db. But you can request an API to do it for you. So the backend needs to take care of that. There are also serverless services, that allow you to write stuff without needing to host a backend

Message permanent page

— If you just want to add an object to an array temporarily (as part of an app) you can simply do myFruits.push({kcal: 223})

Message permanent page

— I want it permanently. Maybe it's unusual but the app would be only for personal use

— If the app is only local you might as well use cookies or localStorage.

— Maybe he wants to save related data to server?