replace

fun replace(token: T, newToken: T): Boolean(source)

The replace() method of the DOMTokenList interface replaces an existing token with a new token. If the first token doesn't exist, replace() returns false immediately, without adding the new token to the token list.

MDN Reference