I can not find an explanation in google map construction:

phones = ["iPhone 7", "LG G 5", "Honor 9", "Idol S4", "Nexus 6P"]; phone: Observable<string>; showPhones() { this.phone = Observable.interval(500).map(i=> this.phones[i]); } 

Namely interests:

 map(i=> this.phones[i]); 

Very similar to the foreach method in the map, but not quite, so that there would be no ambiguity I decided to clarify with you that there would be no more doubts. (Just in case, I’ll clarify that the code snippet was written in TypeScript, but I met exactly this in JS)

  • one
  • one
    By iterating through the array, it returns a new one, but for example a little changed, or you can use it to create templates as in React ES6. map(i=> <div>{this.phones[i]}</div>); i.e. You will receive a new array, already with <div /> elements between which there will be a text with the name of each phone. Although you can take from this.phones right away .map(el => el) , where el will be the phone name - Vasily Barbashev

2 answers 2

The map one purpose to insert a new value into the stream. That is, if there were no map , then in the next step there would be a value equal to i . And so there will be a return value, which in your cases is an array element.

And without seeing the whole structure, I can say that it is in this form that it seems not quite normal.

    Thank you all for the answers, in the Internet, I found the exact answer to my question. Maybe someone will come in handy, this design has the name - "arrow functions", well, then in the internet a lot of material and examples are painted on this topic.