0

For one of my projects, I am required not to use a database to store data in memory. Instead, I must use data structures for that.

I tried to search the web but can't find good ressources that help to do that.

Data I have to handle are api endpoints. How can deal with it?

  • Almost anything you can think of can be modeled with JavaScript's array and object. Really, a let database = {} is all you need. If you explain more about how your data looks like I can try posting an answer. – norbert May 1 '19 at 16:56
  • Thank you for your answer. As an example I want to create a new user via a sign up form. I have input firstname, lastname and email. Then the user clicks register button to sign up. How can I save this data with data structure (and not dbms)? – bam May 1 '19 at 17:07
0

So this answer is based on your comment. Think of it this way, you have three pieces of information which are name value pairs. For example:

firstName: Jon,
lastName: Doe,
email: jdoe@cloud.com

So turning this into an object in JavaScript is literally:

let user = {
  firstName: 'Jon',
  lastName: 'Doe',
  email: 'jdoe@cloud.com'
}

Now you want to save it to your database:

let db = {};
db['user'] = user;

console.log(db);

// prints
{
  user: {
    firstName: 'Jon',
    lastName: 'Doe',
    email: 'jdoe@cloud.com'
  }
}

| improve this answer | |
0

You might be looking for state management. An interesting article: https://codeburst.io/state-management-in-javascript-15d0d98837e1

Some very well know libraries that help you are Redux and Vuex.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.