Intro
Okay, so I have a basic problem, I’ve been given a job to do, however, it’s 110% front end, I have 0 access to any back end tech, no back end scripting, no SQL, nout… This job is actually horrible in one sense, with this specific problem, I’m working with a huge data set, I mean this data set is so unrealistically huge that the multi dimensional array I’ve written is actually over 1,000 lines long, and it’s just filled with content that’s meant to APPEAR like it’s dynamic content.
Don’t ask as to why I have 0 back end access, I’ve brought it up myself, and I found very quickly that I was wasting my breath. * headache * … So I’ve had to mimic dynamic content, using JS alone.
Source Code - The Structure Of The Array
An example of what my array looks like would be something like this:
var array;
....
['String', float, float, 'String', 'String', 'String',
[
[
'String||',
''
],
[
'String||',
''
]
],
'String'
], ......
Now the multi dimensional array itself runs more than fast enough, I won’t lie, I assumed due to the sheer size of it that it may perform a little slow, but I’ve been having no issues in relation to performance on any web browser. I mean I know I could’ve used objects or whatever, but it turns out that this is more than fast enough as it is, surprisingly, and there’s so much data, I’m not gonna go back and change all entries for syntax preferences. I will openly admit, I would have done this differently if I had known that I was going to be handling this much data, when I first started this task, I had 3 entries of data, so as you can imagine, the array was nice and small, and at a very exponential rate, the size of the data set grew.
Explenation
I hope it’s not just me that finds this disgusting. I think this is terrible, I mean I come from a full stack background, so doing EVERYTHING front end just seems so wrong. I personally think I need to find a more elegant solution, while there’s 0 performance issues, and there appears to be 0 bugs with the code I’ve written, it’s so ugly and annoying to maintain.
While it’s not of much importance, if you must know the purpose of this application, it’s basically just adding a TONNE of elements to a static page, images mostly, then the nested arrays are basically the blocks of content, one of the nested arrays goes into some DOM element, the other goes into a completely different DOM element, hence why they’re split up.
It almost looks like you’re getting dynamic content through ajax, only obviously you’re not.
And seriously… I cannot stress how shocked I am that there is NO performance hit with this array, I mean even on mobile devices, if I wasn’t the one building this page, I would’ve assumed that data was all set and brought in via the back end.
Finally
Does anyone have any recommendations on how to make this code more maintainable & easier to read?
This is surprisingly very fast, I mean for each element of this array, it dumps the data into an element, and that element is basically meant to act like an object then. I would use objects, but I may as well do it this way because these elements only gather the data when you click on this element.
For an example of what I mean, here’s a fiddle: https://jsfiddle.net/xaunr1ry/