<commit_before># Preallocation

Instead of declaring a new `Array` and reserving memory for it, you can reallocate an `Array` previously declared.

For that, you need to remove the previous contents of the array. You can do that setting [`Array.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) to 0:

```js
var array = [1, 2, 3, 4, 5]

array = [] //  bad
array.length = 0 // good!
```

Another good tip is to reserve the necessary memory space for your `Array` by setting its `.length` beforehand.

```js
var array = []
arr.length = 5

arr[0] = 1
arr[1] = 2
arr[2] = 3
```<commit_msg>Extend section<commit_after># Preallocation

Instead of declaring a new `Array` and reserving memory for it, you can reallocate an `Array` previously declared.

For that, you need to remove the previous contents of the array. You can do that setting [`Array.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) to 0:

```js
var array = [1, 2, 3, 4, 5]

array = [] //  bad
array.length = 0 // good!
```

Another good tip is to reserve the necessary memory space for your `Array` by setting its `.length` beforehand.

```js
var array = []
arr.length = 5

arr[0] = 1
arr[1] = 2
arr[2] = 3
```

That useful when you want to use an `Array` as temporal data buffer. [array-list](https://www.npmjs.com/package/array-list) is a good library for that.
{'fraction_non_alphanumeric': 0.12741046831955924, 'fraction_numerical': 0.01928374655647383, 'mean_word_length': 4.027681660899654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3704781', 'n_tokens_mistral': 499, 'n_tokens_neox': 452, 'n_words': 185}