Skip to content

Commit 9e7bd10

Browse files
authored
Update create-arrays.md
1 parent 96ff328 commit 9e7bd10

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/tips/create-arrays.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ If you want to create an array pre-filled with some content use the ES6 `Array.p
1212
const foo:string[] = new Array(3).fill('');
1313
console.log(foo); // ['','',''];
1414
```
15+
16+
If you want to create an array of a predefined length with calls you can use the spread operator:
17+
18+
```ts
19+
const someNumbers = [...new Array(3)].map((_,i) => i * 10);
20+
console.log(someNumbers); // [0,10,20];
21+
```

0 commit comments

Comments
 (0)