rxjs map code example
Example 1: rxswift map
func transformUsingMap() -> Observable<String> {
return Observable.of(1, 2, 3)
.map { String("\($0)") }
}
func arrayToNewObject(items: [Item]) -> [Data] {
return items.map({ item in
return Data(item)
})
}
Example 2: javascript map
const myArray = ['Sam', 'Alice', 'Nick', 'Matt'];
const newArray = myArray.map(name => {
return 'My name is ' + name;
});
console.log(newArray);
const anotherArray = myArray.map((value, index) => index + ": " + value);
console.log(anotherArray);
console.log(myArray);