I have an associate array of :
instrumentLookup: {
hh: {label: 'Hi Hat', type: 'hh'},
kd: {label: 'Kick Drum', type: 'kd'},
o1: {label: 'other1', type: 'o1'},
o2: {label: 'other2', type: 'o2'}
}
I think that this structure is OK, but there may be a better way.
I am trying to create an instrument from this list by this function, where the param addedInstrument
comes in as the same string as the label, so hh
, kd
, o1
, ....:
addInstrument: function(addedIntrument) {
console.warn(addedIntrument);
var newLabel = this.defaults.instrumentLookup.addedIntrument.label;
var newType = addedIntrument;
console.warn(newLabel + ' ' + newType)
// push it to the list
// this.unusedInstruments.push({label:newLabel, type:newType});
}
There are a few questions in this, feel free to answer any or all or suggest an alternative:
- How do you access Object properties when the Object is the value of an associative array?
- Should I change it to an array[] of nested objects{type: {other attrs}} from an Associate array?