Question:
I need to create a variable array with index (name) = value, referring to html, example of what this array would look like:Answer:
You are trying to create an object with properties, not an array. If you are coming from another language, then it may be confusing that JavaScript uses array-like syntax to access properties (called bracket notation).You can use
reduce
because you are reducing multiple elements of an array to a single object:If you have better answer, please add a comment about this, thank you!