Objective: My goal is to work with a list of n strings, assign them referential values, and display them as rows in an HTML table.
--- Overview ---
Firstly, I will start with a list of n strings:
'object1'
'object2'
'object3'
...etc.
Next, I aim to match these strings with other data obtained through API calls to determine their properties:
name: 'object1', id: 00112233, count: 25,
name: 'object2', id: 266924, count: 12884,
name: 'object3', id: 312011045, count: 8,
...etc.
Lastly, my plan involves rendering these objects and their properties in a table consisting of n rows on a website:
Name | ID | Count |
--------|-----------|---------|
object1 | 00112233 | 25 |
object2 | 266924 | 12884 |
object3 | 312011045 | 8 |
...etc. | ...etc. | ...etc. |
--- My Approach ---
To begin, I consider storing the original list of n strings as an array:
array = [
'object1'
'object2'
'object3'
//...etc.
]
I then use this array to create n objects within another array:
objArray = array.map(e => {
return{name: e};
});
Subsequently, I iterate through this array of objects to add properties and specific values:
for (let i = 0; i <= objArray.length; i++) {
objArray[i].id = <id value from API corresponding to each object name>;
objArray[i].count = <count value from API corresponding to each object name>;
}
The hope is to achieve a structure like this that can be inserted into an HTML table or similar:
objArray = [
{name: 'object1', id: 00112233, count: 25},
{name: 'object2', id: 266924, count: 12884},
{name: 'object3', id: 312011045, count: 8},
//etc...
]
--- TLDR ---
Objective: Transform a list of n strings into HTML table rows with associated referential values.
- Seeking feedback on the efficiency of my methodology and if there's room for improvement.
- Exploring techniques to loop through objects in an array and add diverse properties individually.
- Determining the process to inject an array of objects into an HTML table effectively.
Thank you for your assistance! It's my first question here, so any guidance on proper etiquette would be appreciated.