Troubleshooting an Array

Hi,

I’m in the process of building a recipe site that allow the user to select the amount of people they are cooking for, then multiplying the amount of ingredients required. I have the calculation working as a number but I’m struggling to get the ‘words’ i.e. flour, sugar back to the array. To explain the setup, in the database I’m using a ‘tags’ field which returns an array when called in the dynamic page. I’m using .match to isolate the numbers for the calculations but the part I’m struggling with is to then put the adjusted number back alongside the relevant ingredient i.e.

Sugar 250g
Flour 500g

The code I have working so far:

let thisRecipe;
let ingredientNbr = 1;
var peopleTtl;

$w.onReady(function () {

    thisRecipe = $w('#dynamicDataset').getCurrentItem();
    $w('#imageStrip').background.src = thisRecipe.image;
    $w('#recipeName').text = thisRecipe.recipeName;
    $w('#chefName').text = thisRecipe.chefName;
 let ingredients = thisRecipe.ingredients;
 
 var arr = thisRecipe.ingredients;
 var str = arr.toString();
 var matches = str.match(/\d+/g);
    peopleTtl = matches.map(n => n * ingredientNbr);
   console.log()
    console.log(str)
    $w('#removeIngredientBtn').onClick(() => {
            ingredientNbr++;
            $w('#ingredientNbr').value = ingredientNbr;
            peopleTtl = matches.map(n => n*ingredientNbr);
 let string = peopleTtl.join('\n')
            $w('#ingredients').text = string;
        });
        $w('#addIngredientBtn').onClick(() => {
            ingredientNbr--;
            $w('#ingredientNbr').value = ingredientNbr;
            peopleTtl = matches.map(n => n*ingredientNbr);
 let string = peopleTtl.join('\n')
            $w('#ingredients').text = string;
        });
 
});

Thank you :slight_smile:

Would anyone be able to help with this one?

You have to put inside:

$w.onReady(function () {
$w('#dynamicDataset').onReady(() => {
//here
})
})

Otherwise it’d try to get the item before the dateset is ready.