How to set an output pin with a variable

I’m trying to set an output pin based on a variable from an array. So in the following function I’d like to use the variable pinNumber which comes from a list instead of DigitalPin.P1
Is there a way to set an output pin using a variable?

function flashyVar () {
    for (let index = 0; index < Seconds; index++) {
        basic.showNumber(DisplaySeconds)
        pins.digitalWritePin(DigitalPin.P1, 1)
        basic.pause(500)
        DisplaySeconds += -1
        basic.pause(500)
    }
    pins.digitalWritePin(DigitalPin.P0, 0)
    DisplaySeconds = Seconds
    basic.showNumber(DisplaySeconds)
}

You can use an array of pins. Something like:

const outputs = [DigitalPin.P1, DigitalPin.P2, DigitalPin.P3];

Then you can pick a specific pin by index (outputs[i]) for digitalWritePin().