Search code examples
javascriptarraysbbc-microbit

Adding a different value of the same variable to an array


Using my micro:bit I am trying to add the value of a variable called sendText to an array without overwriting its previous stored value for that variable.

input.onGesture(Gesture.Shake, () => {
    list.push(sendText)
    binSend = 0
    basic.showString(sendText)
})

My array is called list

let list: string[] = []

I am trying to store single characters in an array then outputting them. If there is a better alternative to using an array I would gladly accept it.


Solution

  • To add a value to an array you use push function, after, if you need to group the characters pushed to array for output you could to use for your specific example list.join('')