=ArrayFormula(SEQUENCE(MAX(ROW(B2:B)*(B2:B<>""))-1))
π Generating an ID Column in Google Sheets
Ben Collins provides a formula for generating a list of IDs or numbers dependent on how many items are in the list using the Sequence formula: