Hi all,
So here i am, a php developer that is use to using arrays in all sorts of ways all the time, i was like okay javascript’s array’s will most likely have the same or close to syntax, so start coding…one day later and a little bold spot on my head from scratching so much i’m admitting defeat and asking the fine people here for help.
I start explaining here
I started to code my multidimensional array as i would in php (i know every language has it’s own ways)
What i did was:
// $ <--- i use this to know it's a variable
array[$category][$subCate] = $subCateName;
Then i learned that arrays only use numerical values for keys and what i want is a object which you can change the key to your liking so i changed my array to a object
{}
but then i learned that you can’t just go and make the object as i did above, you need to do something like this because i’m using variables for keys
array[$category] = $subCate;
array[$category][$subCate] = $subCateName;
i do the above because i want to have the keys set dynamically and you can’t for some reason have a variable in object brackets because it will be used literal why javascript??
This is the object i need and i have no clue what to do to get it so. Little side note, as you can see subCate has multiple children so i did try to use push to push the other objects in but i learned that push is only for arrays as well
{
categoryName1:{
subCatName1:{
someKey: Val,
someOtherKey: Val
}
}
}
Does anyone have some advice for me to get my objects to be like the above? how would i construct this?
Thank you all for ready