I keep encountering an issue with the following message: "Cannot set property '0' of undefined"
var arrItems = {
'product1': [],
'product2': [],
'product3': []
};
var temArr = {};
var dataFor = "";
function fnAddItem(elm, itemInd, rem) {
if (elm != "" && elm != undefined) {
var _name = $(elm).attr("data-name");
var _id = $(elm).attr("data-id");
var _in = $(elm).attr("data-index");
itemInd = _in;
*arrItems[dataFor][_in] = {
'name': _name,
'id': _id,
'index': _in
};*
console.log(arrItems[dataFor][_in]);
}
var strHtml = "";
$.each(arrItems[dataFor], function(key, value) {
if (value['name'] != undefined || value['name'] != null)
strHtml += '<div onclick="fnRemoveItem(this,0,\'' + dataFor + '\');" class="__selected_item" data-remove="' + value['index'] + '"><span>' + (value['index'] == 1 ? value['index'] : "") + value['name'] + (value['index'] == 3 ? value['index'] : "") + '</span><span class="x">×</span></div>';
console.log(strHtml);
});
}