# 6.3 Functions that Operate on Arrays

In this section, we describe the functions that accept all types of arrays.

### `function`arraypobjectâ€‹

This function returns `t` if `object` is an array (i.e., a vector, a string, a bool-vector or a char-table).

``(arrayp [a])     â‡’ t(arrayp "asdf")     â‡’ t(arrayp (syntax-table))    ;; A char-table.     â‡’ t``

### `function`arefarr indexâ€‹

This function returns the `index`th element of the array or record `arr`. The first element is at index zero.

``(setq primes [2 3 5 7 11 13])     â‡’ [2 3 5 7 11 13](aref primes 4)     â‡’ 11``
``(aref "abcdefg" 1)     â‡’ 98           ; â€˜bâ€™ is ASCII code 98.``

See also the function `elt`, in Sequence Functions.

### `function`asetarray index objectâ€‹

This function sets the `index`th element of `array` to be `object`. It returns `object`.

``(setq w (vector 'foo 'bar 'baz))     â‡’ [foo bar baz](aset w 0 'fu)     â‡’ fuw     â‡’ [fu bar baz]``
``;; copy-sequence copies the string to be modified later.(setq x (copy-sequence "asdfasfd"))     â‡’ "asdfasfd"(aset x 3 ?Z)     â‡’ 90x     â‡’ "asdZasfd"``

The `array` should be mutable. See Mutability.

If `array` is a string and `object` is not a character, a `wrong-type-argument` error results. The function converts a unibyte string to multibyte if necessary to insert a character.

### `function`fillarrayarray objectâ€‹

This function fills the array `array` with `object`, so that each element of `array` is `object`. It returns `array`.

``(setq a (copy-sequence [a b c d e f g]))     â‡’ [a b c d e f g](fillarray a 0)     â‡’ [0 0 0 0 0 0 0]a     â‡’ [0 0 0 0 0 0 0]``
``(setq s (copy-sequence "When in the course"))     â‡’ "When in the course"(fillarray s ?-)     â‡’ "------------------"``

If `array` is a string and `object` is not a character, a `wrong-type-argument` error results.

The general sequence functions `copy-sequence` and `length` are often useful for objects known to be arrays. See Sequence Functions.