Added Info About ForEach() Method (#34133)
Added a section on the very commonly used forEach() method for arrays. Also improved sentence structure of previous sentences.
This commit is contained in:
@ -21,7 +21,7 @@ let names: Array<string> = ['Javier', 'Emma', 'John', 'Sophia', 'Emma'];
|
||||
|
||||
## Built-in methods
|
||||
In Typescript's Array type you can use some built-in functions. Each type has common and unique methods.
|
||||
Below you can read about the most used ones of the array type's methods. In the example, we will use the array declaration from above.
|
||||
Below you can read about the most used methods of the Array type. In the example, we will use the array declaration from above.
|
||||
|
||||
### pop()
|
||||
Removes the last element from an array and returns with it.
|
||||
@ -50,4 +50,15 @@ var reverseNames = names.reverse();
|
||||
//reverseNames = ['Emma','Sophia','John','Emma','Javier']
|
||||
```
|
||||
|
||||
### forEach()
|
||||
Perform a designated task for every item in the array
|
||||
```typescript
|
||||
var exclamationPointNames = names.forEach(doSomething);
|
||||
//doSomething = function (name: string, index: number) {
|
||||
// name[i] = name[i] + "!";
|
||||
//}
|
||||
//exclamationPointNames = ['Emma!','Sophia!','John!','Emma!','Javier!']
|
||||
```
|
||||
|
||||
|
||||
[More methods and description at TutorialsPoint](https://www.tutorialspoint.com/typescript/typescript_arrays.htm)
|
||||
|
Reference in New Issue
Block a user