# Why is the List.push() method not working in this example?

**URL:** <https://forum.dfinity.org/t/why-is-the-list-push-method-not-working-in-this-example/8600>\
**Category:** Language Support\
**Created:** [November 15, 2021, 2:47pm UTC](https://forum.dfinity.org/t/why-is-the-list-push-method-not-working-in-this-example/8600 "2021-11-15T14:47:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [November 15, 2021, 2:47pm UTC](https://forum.dfinity.org/t/why-is-the-list-push-method-not-working-in-this-example/8600/1 "2021-11-15T14:47:51Z")

</div>

I tried changing things around but the push isn’t working. Any help would be appreciated.

[https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=3563088652](https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=3563088652)

Here’s the code incase the playground link gets wiped:

```auto
import List "mo:base/List";

actor {
  stable let listOfNumbers = List.nil<Nat>();

  public query func getListSize(): async Nat {
    return List.size(listOfNumbers);
  };

  public func addToList(n: Nat): async () {
    ignore List.push(n, listOfNumbers);
  };
}

```

---

<div class="post-metadata">

**Author:** ![quint](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/quint/32/40449_2.png) [@quint](https://forum.dfinity.org/u/quint)\
**Post date:** [November 15, 2021, 4:41pm UTC](https://forum.dfinity.org/t/why-is-the-list-push-method-not-working-in-this-example/8600/2 "2021-11-15T16:41:03Z")

</div>

This is because `List.push` returns a new list with `n` pushed to `listOfNumbers`. It does not change `listOfNumbers` itself. So you would want the following:

```auto
// `var` instead of `let`, so you can re-assign it.
stable var listOfNumbers = List.nil<Nat>();

// ...

// Update `listOfNumber` to the new list with `n` added to it.
listOfNumbers := List.push(n, listOfNumbers);

```

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [November 15, 2021, 5:14pm UTC](https://forum.dfinity.org/t/why-is-the-list-push-method-not-working-in-this-example/8600/3 "2021-11-15T17:14:17Z")

</div>

Any idea if this has the same kind of drawback that `Array.append` has as documented [here](https://smartcontracts.org/docs/base-libraries/Array.html#append)

---

<div class="post-metadata">

**Author:** ![quint](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/quint/32/40449_2.png) [@quint](https://forum.dfinity.org/u/quint)\
**Post date:** [November 16, 2021, 8:58am UTC](https://forum.dfinity.org/t/why-is-the-list-push-method-not-working-in-this-example/8600/4 "2021-11-16T08:58:37Z")

</div>

It should not have, since it is not reconstructing anything afaik, just pre-pending.
