Modify query param in pre-request script

I need to programmatically set a query parameter on my request. Up until a week or two ago I was able to do the following, and it worked:

//url: env.com/path?param1

// update param1 to new value
let queryParam1 = 'whatever';
pm.request.url.query[0] = queryParam1;

This doesn’t work anymore. How do I modify (or add) a query parameter to my request in the pre-request script?

Seems I can do it like this now, but I’d still like to know if there’s a “right” way so my scripts don’t break again:

pm.request.url.query.add(‘param1=’ + paramValue);