1

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?

2
  • 1
    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.
    – Sam R.
    Commented May 1, 2019 at 16:56
  • 1
    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)? Commented May 1, 2019 at 17:07

2 Answers 2

1

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: [email protected]

So turning this into an object in JavaScript is literally:

let user = {
  firstName: 'Jon',
  lastName: 'Doe',
  email: '[email protected]'
}

Now you want to save it to your database:

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

console.log(db);

// prints
{
  user: {
    firstName: 'Jon',
    lastName: 'Doe',
    email: '[email protected]'
  }
}

0
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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