I find myself in a predicament where I need to dynamically add elements to a multidimensional array depending on a specific condition. This means that the type of element to be added will vary based on the condition.
if(type == 'text-box'){
var title = jQuery("#textbox-title-"+id).val();
var desc = jQuery("#textbox-desc-"+id).val();
eleDetails[id]['content'] = {title:title, content:desc};
}
else if(type == 'image-box'){
var title = jQuery("#imagebox-title-"+id).val();
var imgurl = jQuery("#imagebox-url-"+id).val();
var desc = jQuery("#imagebox-desc-"+id).val();
eleDetails[id]['content'] = {title:title, imgurl:imgurl, content:desc};
}
Can anyone suggest an efficient way to achieve this task?