How to loop through the alphabet via underscoreJS

后端 未结 9 1575
情话喂你
情话喂你 2021-01-04 01:05

I\'m using Underscore\'s template() method in BackboneJS views. I\'d like to show a list of alphabet letters in my view in order to sort a collection by letter.

As a

9条回答
  •  北海茫月
    2021-01-04 01:48

    Using ES6 for-of:

    for(let char of "abcdefghijklmnopqrstuvwxyz" )
      console.log(char); // prints 'a' to 'z'
       

    Pretty easy to use that in a template, and you could use Babel to transpile it to code for browsers which lack support for that syntax.

提交回复
热议问题