0

In Javascript, I would like to assign subarray with name from a variable, I can hardcode the proArr to have subarray "create" and "update" as per below...

proArr.create = ...
proArr.update = ...

however, I'd like to dynamically assign the name of the subarray instead, something like this...

let func = "create";
upload(func);
.
.
.
function upload(func){
proArr.(func) =

I'm sure this question has been asked many times, but being a newbie I'm not getting results likely not asking the right terms. Any pointer is greatly appreciated.

user1488934
  • 247
  • 2
  • 5
  • 13
  • Arrays don't have named keys in JS. Yes, you can assign one, because arrays are, ultimately, still just objects, but then you really should just be declaring your own type that extends Array, with its own class (or prototype) functions added on so you don't pollute the array prototype, and you don't end up with code that's constantly assigning the exact same properties, but maybe not always, even when it should. – Mike 'Pomax' Kamermans Nov 11 '21 at 00:34
  • That's an object and a property, not an array. – Barmar Nov 11 '21 at 00:34
  • 1
    `proArr[func] = ...` – Barmar Nov 11 '21 at 00:34
  • @Barmar, work perfectly!! – user1488934 Nov 11 '21 at 00:40

0 Answers0