const ids = ['buttonA', 'buttonA1',... 'ccontent5']; let {buttonA, buttonA1, ... ccontent5} = ids.reduce ((obj, name) => (obj[name] = document.querySelector('#'+name), obj), {});