> For the complete documentation index, see [llms.txt](https://garden.famiclone.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://garden.famiclone.dev/development/programming-languages/javascript/arrays.md).

# Arrays

### Sort array

```
const numbers = [10, 7, 2901, 3.5];
numbers.sort((a, b) => a - b); // ascending
```

### Bubble sort

```
const bubbleSort = arr => { let sorted;
  do { sorted = false;
    for (let i = 0; i < arr.length - 1; i += 1) {
      if (arr[i] > arr[i + 1]) {
        const temp = arr[i]
    
        arr[i] = arr[i + 1]
        arr[i + 1] = temp;
    
        sorted = true
      }
    }
  } while (sorted)
  return arr;
}
```
