So, I want to have an object with dynamic property names, retrieving from an array. This is what I've tried so far:
var fruits = {};
var props = ['orange', 'apple', 'banana'];
for (var i = 0; i < props.length; i++) {
fruits.props[i] = 'Juice';
}
My object should look like this:
fruits { orange: 'Juice', apple: 'Juice', banana: 'Juice' };
But I'm getting the error:
Uncaught TypeError: Cannot set property '0' of undefined(…)
What am I doing wrong?
Edit:
Not because the question title is similar, the question itself has to be as well. This question is different from 695050 because I'm not retrieving my property names from the DOM. I'm trying to loop an array and it tends to cause a confusion when working with the brackets notation.