# Issue with javascript array handling

**URL:** <https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046>\
**Category:** Runtime Framework\
**Tags:** server-framework\
**Created:** [February 26, 2025, 10:37am UTC](https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046 "2025-02-26T10:37:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrDog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mrdog/32/2486_2.png) [@MrDog](https://forum.heroiclabs.com/u/MrDog)\
**Post date:** [February 26, 2025, 10:37am UTC](https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046/1 "2025-02-26T10:37:57Z")

</div>

I am writing an authoritarian card game. Im using typescript to write the server side logic. My issue is that in the first round everything works as expected. But when i begin a new round afterwards in the same match, the array stops working as expected. When i splice the array it doesnt shorten it, instead it inserts null values at the end. It also doesn’t add it to the players hand.  
The code:

```auto
protected static dealCardsToPlayer(state: BaseCardGameState, playerIndex: number, numberOfCards: number, broadcast: boolean = true) {
    const playerHand = state.players[playerIndex].hand
    const newCards = state.talon.splice(0, numberOfCards)
    playerHand.push(...newCards)
    ...

```

The game state:  
Before dealing:

```auto
"talon": [
    {
      "suit": 2,
      "rank": 4
    },
    {
      "suit": 2,
      "rank": 2
    },
...
    {
      "suit": 2,
      "rank": 10
    }
  ],
"players": [
    {
      "id": "c54ea6f6-e406-4269-aef0-4f16276dde6b",
      "points": 0,
      "hand": [],
      "team": 0,
      "isReady": false
    },
    {
      "isReady": false,
      "id": "56222023-b567-40c8-9c68-f246e5adc817",
      "points": 0,
      "hand": [],
      "team": 1
    }
  ],

```

After dealing cards:

```auto
"talon": [
    {
      "suit": 3,
      "rank": 3
    },
    {
      "suit": 1,
      "rank": 4
    },
    {
      "suit": 1,
      "rank": 11
    },
    {
      "rank": 11,
      "suit": 3
    },
    {
      "suit": 3,
      "rank": 2
    },
    {
      "suit": 2,
      "rank": 11
    },
    {
      "suit": 2,
      "rank": 3
    },
    {
      "suit": 0,
      "rank": 2
    },
    {
      "suit": 3,
      "rank": 10
    },
    {
      "suit": 2,
      "rank": 10
    },
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null
  ],
"players": [
    {
      "id": "c54ea6f6-e406-4269-aef0-4f16276dde6b",
      "points": 0,
      "hand": [],
      "team": 0,
      "isReady": false
    },
    {
      "id": "56222023-b567-40c8-9c68-f246e5adc817",
      "points": 0,
      "hand": [],
      "team": 1,
      "isReady": false
    }
  ],

```

The crazy part is all these functions work in the first round and somehow stop working when the next round begins.

1. Versions: Nakama 3.5, Docker, Godot client
2. Server Framework Runtime language: TS/JS

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [February 26, 2025, 1:36pm UTC](https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046/2 "2025-02-26T13:36:23Z")

</div>

Hello @MrDog,

There’s a few caveats around the JS runtime due to how Goja (the JS engine written in Go) works - we have some upcoming improvements that should resolve these but they’re still experimental so we can’t promise they’ll be out in the next release.

As a workaround, I think that if you create a new array and push to that instead of the existing one, it should work as expected.

Best.

---

<div class="post-metadata">

**Author:** ![MrDog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mrdog/32/2486_2.png) [@MrDog](https://forum.heroiclabs.com/u/MrDog)\
**Post date:** [February 26, 2025, 4:43pm UTC](https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046/3 "2025-02-26T16:43:39Z")

</div>

Thanks for the info, I will try it with a new array. Would you know when the next version will approximately release?

---

<div class="post-metadata">

**Author:** ![MrDog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mrdog/32/2486_2.png) [@MrDog](https://forum.heroiclabs.com/u/MrDog)\
**Post date:** [February 27, 2025, 1:30pm UTC](https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046/4 "2025-02-27T13:30:24Z")

</div>

Update: I fixed the issue by building my own docker image of this pull request: [Javascript runtime improvements by sesposito · Pull Request #1323 · heroiclabs/nakama · GitHub](https://github.com/heroiclabs/nakama/pull/1323). And now everything works correctly!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [February 27, 2025, 2:08pm UTC](https://forum.heroiclabs.com/t/issue-with-javascript-array-handling/6046/5 "2025-02-27T14:08:06Z")

</div>

That’s good to know, thanks for the update!

Given that the PR is still in `draft` and there’s some more testing to do, if you run into any issues let me know, could be useful information 🙂

Best
