What I'm looking to do is create an object with unique ID's. To better explain here's an example:
var obj = new Object({
'a': {
'someVariable': 'heh',
'someOtherVariable': 'Stuff'
},
'c': {
'someVariable': 'heh',
'someOtherVariable': 'Stuff'
}
});
Thing is, the object is going to be used/passed extensively, adding and removing items, but each item 'identifier' needs to must be unique... The object may hold 0 items at one point, or 700 at another. I felt the easiest way would be to have a number as the identifier for each object (instead of a
or c
) and enumerate over the Object.keys(obj)
, finding the highest number. Sadly, it doesn't appear you can use a number, as when I try to access obj.0
, I get an error.
What I'd like the ID to be ideally is:
- A number would be easiest to work with, although is not 100% necessary if impossible.
- When an object is removed the information it holds will be inserted into a database for tracking purposes, so it's vitally important that the object id remains unique even if that ID is not in the object any longer. This is why I thought numbers would be best, as you could just add +1 to each item.
Anyone know of a way to do this?
Edit for elaboration
The project I'm doing this for is basically a workflow coordinator of sorts. The server side will create the object from various sources, including client side input, and create the object. This object is sent to the client which renders the information. Once completed by the client, the task is complete so it doesn't need to be displayed the next time the server updates the tasks list (by sending the object). The object is then completely removed from the Object, and the information is sent to a database for tracking purposes.