# How to change a value in an array?

**URL:** <https://community.weweb.io/t/how-to-change-a-value-in-an-array/891>\
**Category:** Ask us anything\
**Created:** [July 28, 2022, 6:15pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891 "2022-07-28T18:15:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![khairul](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@khairul](https://community.weweb.io/u/khairul)\
**Post date:** [July 28, 2022, 6:15pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/1 "2022-07-28T18:15:25Z")

</div>

Greetings weweb folks.

I am new to weweb and not much of a coder. I am trying to build a shopping cart array.

Right now I have this array of list of items added to cart, the quantity and other details :  
[  
{name:product1, price:9.99, quantity: 2}  
{name:product2, price:8.99, quantity:3}…  
]

I am trying to figure out how I can change/update the quantity, without changing the order of items. Can you guys share how to it? Thank you so much.

---

<div class="post-metadata">

**Author:** ![kevinwasie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kevinwasie/32/402_2.png) [@kevinwasie](https://community.weweb.io/u/kevinwasie)\
**Post date:** [July 28, 2022, 6:29pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/2 "2022-07-28T18:29:49Z")

</div>

You need to use a custom javascript action.

So, you enter code like this if your array variable is called array:

array[index].name = “product4”;

index is the number of the item in the array. Arrays start at 0 position, so the first item is array[0].

You can use dot notation like that to get or set the value.

---

<div class="post-metadata">

**Author:** ![khairul](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@khairul](https://community.weweb.io/u/khairul)\
**Post date:** [July 28, 2022, 6:46pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/3 "2022-07-28T18:46:36Z")

</div>

Do I need to use change variable value or return? Because I used return and get false as a value

 ![Screenshot 2022-07-29 at 2.46.47 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/f/f5d93befdc21319863a26a0b9d04878d2d2d18e2.jpeg)

---

<div class="post-metadata">

**Author:** ![kevinwasie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kevinwasie/32/402_2.png) [@kevinwasie](https://community.weweb.io/u/kevinwasie)\
**Post date:** [July 28, 2022, 6:48pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/4 "2022-07-28T18:48:35Z")

</div>

Neither. Take out the return unless you want to return something.

Here, it sounds like you just want to set the value.

---

<div class="post-metadata">

**Author:** ![kevinwasie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kevinwasie/32/402_2.png) [@kevinwasie](https://community.weweb.io/u/kevinwasie)\
**Post date:** [July 28, 2022, 6:50pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/5 "2022-07-28T18:50:14Z")

</div>

Oh I see … change the “return a value” to custom javascript:

 ![Screen Shot 2022-07-28 at 2.47.13 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/bc3134df1ad0464b84dd0936b96e4ee50575a24b.png)

---

<div class="post-metadata">

**Author:** ![khairul](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@khairul](https://community.weweb.io/u/khairul)\
**Post date:** [July 28, 2022, 7:10pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/6 "2022-07-28T19:10:29Z")

</div>

Thanks so much for your help, been figuring this since yesterday 😂

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [July 29, 2022, 12:24pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/7 "2022-07-29T12:24:18Z")

</div>

For information, we have developed a way to do it in no code, because lot of people need the feature.  
When doing a “Change variable Value”, you will be able to choose a path and/or an index when modifying an array or object.  
This will be on the next release 🙂

---

<div class="post-metadata">

**Author:** ![khairul](https://avatars.discourse-cdn.com/v4/letter/k/a88e4f/32.png) [@khairul](https://community.weweb.io/u/khairul)\
**Post date:** [July 29, 2022, 4:18pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/8 "2022-07-29T16:18:58Z")

</div>

you guys rock! Thank you so much for this

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [August 4, 2022, 2:19pm UTC](https://community.weweb.io/t/how-to-change-a-value-in-an-array/891/9 "2022-08-04T14:19:53Z")

</div>

And its in production !  
You can now update array and object partially with the “Change variable value” action
