What I want to do is create an object with unique identifiers. To better explain an example here:
var obj = new Object({ 'a': { 'someVariable': 'heh', 'someOtherVariable': 'Stuff' }, 'c': { 'someVariable': 'heh', 'someOtherVariable': 'Stuff' } });
The thing is, the object will be used / transmitted widely, adding and removing elements, but each element identifier must be unique ... An object can contain 0 elements at one point or 700 on another, I felt that the easiest way would be to have a number as an identifier for each object (instead of a or c ) and list by Object.keys(obj) , typing the largest number. Unfortunately, it does not appear, you can use a number, since when I try to access obj.0 , I get an error message.
I would like the ID to be ideally:
- The number will be easiest to work with, although 100% is necessary if this is not possible.
- When an object is deleted, the information it stores will be inserted into the database for tracking purposes, so it is vital that the identifier of the object remains unique, even if that identifier is no longer in the object. This is why I thought the numbers would be better since you can simply add +1 to each element.
Does anyone know how to do this?
Edit for development
The project that I am doing for this is basically a workflow coordinator. The server side will create an object from various sources, including client-side input, and create the object. This object is sent to the client, which displays the information. After completion by the client, the task is completed, so it does not need to be displayed the next time the task list server is updated (by sending an object). Then the object is completely removed from the object, and the information is sent to the database for tracking purposes.
source share