Skip to content

Commit

Permalink
add statement 'alias' information to 'unshift' page
Browse files Browse the repository at this point in the history
  • Loading branch information
ganicke authored Oct 16, 2024
1 parent a16156d commit ece60dd
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions common-docs/reference/arrays/unshift.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
# unshift

Add an element to the front of an array.
Add an element to the front of an array and return the new length of the array.

```sig
[""].unshift("hello");
[""]._unshiftStatement("hello");
[""].unshift("hello")
```
Add an element to the front of an array but don't return the new length of the array.

```sig
[""]._unshiftStatement("hello")
```

You might have an array with 3 numbers, like 1, 2, and 3. If you want to add another number to the front,
then you _unshift_ it into the array. You do it like this:

```block
let thoseNumbers = [1, 2, 3];
let head = 0;
head = thoseNumbers.unshift(0);
let thoseNumbers = [1, 2, 3]
let arrayLength = thoseNumbers.unshift(0)
```

## Parameters

* **item**: the element to add to the front of the array.

## Returns

* the new length of the array.

### ~reminder

#### **shift** statement

The ``||arrays:unshift||`` **statement** only adds an element to the front of the array. It doesn't the array length.

```block
["a", "b", "c"]._shiftStatement()
```

### ~
## Example

Make an array that simulates a train. Place the parts of the train in the right order.
Expand Down Expand Up @@ -47,4 +65,4 @@ while (parts.length > 0) {

## Sea also

[shift](/reference/arrays/shift), [push](/reference/arrays/push)
[shift](/reference/arrays/shift), [push](/reference/arrays/push)

0 comments on commit ece60dd

Please sign in to comment.