So I am working on an application and once a user connects (via soundcloud), the following object:
{userid: userid, username: username, genre: genre, followings: followings}
is pushed into an array:
var users = [];
What I want to be able to do is for when a new user connects, to store this new user's profile object in the users
array, however I want this new connector's profile to append previously logged in users in the array. So that basically the more users that log in, the bigger the array gets, creating a database of users if that makes sense?
Is there a way of doing this in JavaScript?
Thanks!
The best way to accomplish this is what you somewhat hinted at - a database. There are several databases that you could essentially store locally or in the browser cache, jStorage is one I've heard good things about. A simple search for javascript database will probably give you many other good answers.
You could also create a remote db using sqlite or any other database engine to create your container. Note that would would have to either work with an API or define some sort of content management system so you could perform the CRUD operations on the database.
The layout you provided ( {userid: userid, username: username, genre: genre, followings: followings}
) would work fairly well in a database table. You will have to define what your data types are for each of these fields, probably text or number for the user id, text for username, etc, so you can create the tables with the correct data type.
The followings field seems like it will have more than one entry, i.e. it will be a list or array, so you would probably want to create another table to house those entries and then use a primary key or some other identifier to link to it in your first table.
This question may be of some use to you: How to store a list in a column of a database table