# Troubleshooting an Array

**URL:** <https://forum.wixstudio.com/t/troubleshooting-an-array/4343>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [January 25, 2021, 8:21pm UTC](https://forum.wixstudio.com/t/troubleshooting-an-array/4343 "2021-01-25T20:21:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [January 25, 2021, 8:21pm UTC](https://forum.wixstudio.com/t/troubleshooting-an-array/4343/1 "2021-01-25T20:21:04Z")

</div>

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:

```javascript
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 🙂

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [January 26, 2021, 8:04pm UTC](https://forum.wixstudio.com/t/troubleshooting-an-array/4343/2 "2021-01-26T20:04:09Z")

</div>

Would anyone be able to help with this one?

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [January 27, 2021, 12:19am UTC](https://forum.wixstudio.com/t/troubleshooting-an-array/4343/3 "2021-01-27T00:19:23Z")

</div>

You have to put inside:

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

```

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