W
W
Wayne12121212020-10-20 18:45:16
JavaScript
Wayne1212121, 2020-10-20 18:45:16

How to make letter numbering?

How to make the letter numbering go through the loop? A,B,C...Z,AA,AB,AC etc.

In general, we need an analogue as in css, only through js.

counter-increment: col; 
content: counter(col, upper-alpha);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-10-20
@Wayne1212121

methods: {
  createAlphaIndex(num) {
    const base = 26;
    let str = '';

    do {
      const mod = num % base;
      num = num / base | 0;
      str = (mod ? String.fromCharCode('A'.charCodeAt(0) + mod - 1) : (--num, 'Z')) + str;
    } while(num);

    return str;
  },
},

<div v-for="i in 1000">{{ createAlphaIndex(i) }}</div>

https://jsfiddle.net/bh0cep84/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question