<label>
Город:
<select id="city"></select>
</label>
<label>
Линия:
<select id="line"></select>
</label>
<label>
Станция:
<select id="station"></select>
</label>
fetch('https://api.hh.ru/metro/').then(r => r.json()).then(subwayData => {
const city = document.querySelector('#city');
const line = document.querySelector('#line');
const station = document.querySelector('#station');
const getLines = () => subwayData[city.value].lines;
const update = (el, data) => {
el.replaceChildren(...data.map((n, i) => new Option(n.name, i)));
el.dispatchEvent(new Event('change'));
};
city.addEventListener('change', () => update(line, getLines()));
line.addEventListener('change', () => update(station, getLines()[line.value].stations));
update(city, subwayData);
});