Click here to Skip to main content
15,904,494 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have basic knowledges in javascript.

I would like to store data linked to object inside collection containing objects of the same type which :
- stay in memory (not saved into a suport as harddrive, SSD, etc)
- is not called as an array with tablename[colnumber,linenumber]

example of values

OBJECT_1
id = 1
firstname= "john"
lastname = "doe"

OBJECT_2
id = 2
firstname= "david"
lastname = "thomas"


how to :
>>> have the command objectype(ID as option).function_add(ID, firstname, lastname) which add an object in the collection objectype with the followings rules :
** the ID have to be unique (another object cannot already exists
with the same ID).
** if no ID is specified in the parentheses of objecttype: add object after the last object inside the collection objecttype
** if ID is specified in the parentheses of objecttype : add after the object which have indicated ID .
Example : objectype(1).function_add(2, "joe", "din") will add after object with ID 1 inside the collection objectype a new object with properties values ID = 2, firstname = "joe" and lastname = "din"

>>> have the command objectype(ID).function_remove() which remove the object which have the ID inside the collection objectype

>>> have the command objecttype(ID).propertyname which return or set a property (depending if it is on the left or the right of parentheses).
examples:
** objectype(1).firstname = "john" will set value "john" to the
property firstname of the object with ID =1 inside the collection objectype.
** variable = objectype(2).lastname will set to the variable the value of property lastname of the object with ID = 2 inside the collection objectype.

>>> have the command objectype(ID).function_getfullname() which return the value of property firstname joinded to the value of property fullname of the object with ID inside the collection objecttype. Example : objectype(1).getfullname will return "john doe"with the hereabove "object 1" properties values

>>> have the command objectype(ID).function_sort(propertyname) to sort objects inside the collection objecttype with the property named "propertyname"

>>> write **loop throught the objects stored inside the collection objecttype** with kinds of loops which begin with:
** foreach object in objectype { }
** for i = 0 to objectype.length { } ( objectype.length returns the number of objects stored inside the collection objectype )

To better understand, could you give me an equivalent of the data inside the object collection ?
I think that the objects given in example on the beginning will be writed to something which should looklike to the following


[
[id = 1,
firstname= "john",
lastname = "doe"]
,
[id = 2
firstname= "david",
lastname = "thomas"]
]


Thank you very much for your help !

What I have tried:

I have basic knowledges in javascript. I have already looking for solution in lessons and forums but I have not found what I am looking for... I hope I will meet here a developper which will understand my difficulties and will help me to improve my level, and also the for others peoples which will see this article. The central objecttype leads the question cannot be devided to several questions.
Posted
Comments
[no name] 17-Feb-24 14:13pm    
There are 2 aspects to this: data definition and data manipulation. You've skipped the part where "ID, firstname, and lastname" are "defined". The "object" that contains them has also not been defined. If on the other hand, you were dealing with "unnamed" generic objects and collections / "bags", that would be a different matter; and can be handled more "generically".
Member 16203518 18-Feb-24 4:26am    
Thank you for your answer. So, how can I do it ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900