Convert string to variable name in JavaScript September 29, 2022 by Tarik If it’s a global variable then window[variableName] or in your case window["onlyVideo"] should do the trick.