I have multiple products on my page and want to create an associative array holding the product number as key and the JQuery element as value so I created this interface
interface ProductMap<T extends JQuery> {
[productNumber: string]: T;
}
Then, in my class, I initialize it protected elements: ProductMap<JQuery> = {}; and want to fill it with data later on
const products = $(selector);
if (products.length > 0) {
$.each(products, function (index, product) {
this.elements[$(product).data('product-number')] = $(product);
});
}
However, I'm always getting the error
Uncaught TypeError: Cannot set property '{product-number}' of undefined
How exactly do I create such an associative array?