---
title: toArray()
framework: javascriptcore
role: symbol
role_heading: Instance Method
path: javascriptcore/jsvalue/toarray()
---

# toArray()

Converts the JavaScript value to an array.

## Declaration

```swift
func toArray() -> [Any]!
```

## Return Value

Return Value The array representation of the value.

## Discussion

Discussion If the value is a JavaScript object, this method reads the object’s length property as an unsigned integer, creates an NSArray object of the corresponding size, and recursively copies and converts any properties corresponding to indices within the array bounds. JavaScript converts each element to a native object using the rules listed in Convert Between JavaScript and Native Types. This method returns nil if the JavaScript value is null or undefined, and throws a JavaScript TypeError if the value is not a JavaScript object.

## See Also

### Reading and Converting JavaScript Values

- [toObject()](javascriptcore/jsvalue/toobject().md)
- [toObjectOf(_:)](javascriptcore/jsvalue/toobjectof(_:).md)
- [toBool()](javascriptcore/jsvalue/tobool().md)
- [toDouble()](javascriptcore/jsvalue/todouble().md)
- [toInt32()](javascriptcore/jsvalue/toint32().md)
- [toUInt32()](javascriptcore/jsvalue/touint32().md)
- [toNumber()](javascriptcore/jsvalue/tonumber().md)
- [toString()](javascriptcore/jsvalue/tostring().md)
- [toDate()](javascriptcore/jsvalue/todate().md)
- [toDictionary()](javascriptcore/jsvalue/todictionary().md)
- [toPoint()](javascriptcore/jsvalue/topoint().md)
- [toRange()](javascriptcore/jsvalue/torange().md)
- [toRect()](javascriptcore/jsvalue/torect().md)
- [toSize()](javascriptcore/jsvalue/tosize().md)
