Skip to content

Commit

Permalink
add statement 'alias' information to 'shift' page
Browse files Browse the repository at this point in the history
  • Loading branch information
ganicke authored Oct 16, 2024
1 parent 1a3549c commit a16156d
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions common-docs/reference/arrays/shift.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
Remove and return the first element from an array.

```sig
[""].shift();
[""]._shiftStatement();
[""].shift()
```

Remove the first element from an array but don't return it.

```sig
[""]._shiftStatement()
```

The first element in the array is removed, so the array becomes smaller by one element.
Expand All @@ -13,29 +18,39 @@ If you have an array with 4 numbers, like 1, 2, 3, and 4, you remove the first n
by _shifting_ it from the front. To shift the number from the array in blocks, do this:

```block
let thoseNumbers = [1, 2, 3, 4];
let firstNumber = thoseNumbers.shift();
let thoseNumbers = [1, 2, 3, 4]
let firstNumber = thoseNumbers.shift()
```

## Returns

* the first element in the array.

### ~reminder

#### **shift** statement

The ``||arrays:shift||`` **statement** only removes the first element from the array. It doesn't return it.

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

### ~
## Example

Find out how many odd numbers there are as you remove all the numbers from a list.

```blocks
let odds = 0;
let ints = [45, 78, 98, 3, 5, 6, 12, 643, 0, 34, 4];
let odds = 0
let ints = [45, 78, 98, 3, 5, 6, 12, 643, 0, 34, 4]
while (ints.length > 0) {
if ((ints.shift() % 2) > 0) {
odds++;
odds++
}
}
```

## See also

[unshift](/reference/arrays/unshift), [pop](/reference/arrays/pop)

0 comments on commit a16156d

Please sign in to comment.