okay I’m pretty noob but have been enjoying the recursive-ness of js
I’m [hopefully] making expandable info boxes that operate independently.
Instead of making 5 different animation/onClick() behaviours for each one, I figure I’ll name all the elements to a specification i made up (because sadly i’m in wix/velo and I need to refer to them as $(‘#element’), etc) and then generate an object that contains the strings to plug in as arguments.
After some mind blowing moments, I was successful (yes I’m dumb).
here is my final output that gives me each category and their array with the strings
heres the code if the image didn’t load:
let parts = ["Win')", "List')", "Text')", "ArL')", "ArR')"];
let cats = ["$w('fam", "$w('mwl", "$w('aes", "$w('hrm"];
function merger(c, p) {
let result = [];
let i;
for (i = 0; i != p.length; i++) result[i] = c + p[i];
return result;
}
const final = {
fam: merger(cats[0], parts),
mwl: merger(cats[1], parts),
aes: merger(cats[2], parts),
hrm: merger(cats[3], parts)
};
//object made with category: [string1, string2,...] for each
console.log (final);
I know {final} could be improved but that brings me to my actual question(s).
My animation/onClick() function (not pictured, happens after); if it was to run independently for each category, it needs the strings in the array of each category, which thankfully I managed to generate.
However I’d rather not refer to them literally from the array like categoryStr[0] because then I’d still kinda have to copy/paste the function [i] times for each category, no?
So how can I turn all the strings in each array of this object I’ve made into objects themselves, so that way the functions I do later only need to refer to a single object like ‘for each {category}Str.Text” instead of for famStr[i], for hrmStr[i], etc.
Like later I’d hope to make a for loop or something that executes my future “interactiveFunction(category)” for all my categories using each of their variable lists in a tidy way, but hitting that goal is just beyond me, I figure I can do that if the variable list is clean and I just reference a neat object like ‘category.param’ instead of ‘category[2]’. idk data types and valid references haven’t quite settled for me yet. I figure a first post would usually be embarrassing but hey I’m drunk, head-scratching, and an outside perspective from StackOverflow peeps would really help me rn along with all the docs i’ve been reading. Maybe it’s time to hire a tutor…