Array.from + itérateur

let range = {
  from: "A",
  to: "W"
};

// 1. call to for..of initially calls this
range[Symbol.iterator] = function() {

  // 2. ...it returns the iterator:
  return {
    current: this.from,
    last: this.to,

    // 3. next() is called on each iteration by the for..of loop
    next() {
      // 4. it should return the value as an object {done:.., value :...}
      if (this.current <= this.last) {
let char = this.current;
this.current = String.fromCharCode(this.current.charCodeAt(0)+1);
        return { done: false, value: char };
      } else {
        return { done: true };
      }

    }
  };
};

for (let num of range) {
  console.log(num);
}

let t = Array.from(range,c=>c.toLowerCase());
console.log(t);

code


JS Bin on jsbin.com