I am building a form that sells tickets for an animal clinic. I am collecting information about each animal for each ticket. My goal is to add an array of options (addOpts) to a master array (allOpts) but everything I try only concatenates to the master array. This is done per animal on an individual page which triggers this code when the “next” button is hit, so that the next animal info page will also trigger and add a new array into the master.
//SET OPTIONS
export function addOns(e) {
increment();
let addOpts = [];
let total = [];
let allOpts = [];
let allTotal = [];
let selected = $w('#addons'+inc).selectedIndices;
if(selected.includes(0)){
addOpts.push("rabies");
total.push("rabies");
}else if($w('#rabiesReq'+inc).checked){
addOpts.push("rabies");
total.push("rabies");
}else{
addOpts.filter(e => e !== 'rabies');
total.filter(e => e !== 'rabies');
}
if(selected.includes(1)){
addOpts.push("dog vax");
total.push("dogvax");
}else{
addOpts.filter(e => e !== 'dog vax');
total.filter(e => e !== 'dogvax');
}
if(selected.includes(2)){
addOpts.push("cat FVRCP");
total.push("fvrcp");
}else{
addOpts.filter(e => e !== 'cat FVRCP');
total.filter(e => e !== 'fvrcp');
}
if(selected.includes(3)){
addOpts.push("cat FVRCP + FeLV");
total.push("fvrcpfelv");
}else{
addOpts.filter(e => e !== 'cat FVRCP + FeLV');
total.filter(e => e !== 'fvrcpfelv');
}
if(selected.includes(4)){
addOpts.push("microchip");
total.push("microchip");
}else{
addOpts.filter(e => e !== 'microchip');
total.filter(e => e !== 'microchip');
}
if(selected.includes(5)){
addOpts.push("heartworm test");
total.push("heartworm");
}else{
addOpts.filter(e => e !== 'heartworm test');
total.filter(e => e !== 'heartworm');
}
if(selected.includes(6)){
addOpts.push("FeLV test");
total.push("felv");
}else{
addOpts.filter(e => e !== 'FeLV test');
total.filter(e => e !== 'felv');
}
if(selected.includes(7)){
addOpts.push("revolution");
total.push("revolution");
}else{
addOpts.filter(e => e !== 'revolution');
total.filter(e => e !== 'revolution');
}
if(selected.includes(8)){
addOpts.push("ear clean");
total.push("ears");
}else{
addOpts.filter(e => e !== 'ear clean');
total.filter(e => e !== 'ears');
}
if(selected.includes(9)){
addOpts.push("nail trim");
total.push("nails");
}else{
addOpts.filter(e => e !== 'nail trim');
total.filter(e => e !== 'nails');
}
allOpts.push([addOpts]);
allTotal.push([total]);
}
With this I get
allOpts [1,2,3,4]
but what I want is
allOpts[ [1,2], [3,4] ]
I’ve also tried changing the final pushes to the code below with the same outcome.
allOpts.push(addOpts);
allTotal.push(total);
My goal is to create a master array which I can then manipulate the contained data later.