FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

ToArray

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

ToArray( object )
to_array( object )
ToArray( object )
ToArray( object )
ToArray( object )
ToArray( object )

Description

The ToArray function converts an Object to an Array, if possible.

If conversion cannot be completed, for any reason, an "invalid argument" error is returned.

Parameters

Parameter Type Definition and Requirements

object

Object

The Object to convert to an Array.

Returns

An Array composed from the provided object.

Examples

The following query uses ToArray to convert an object into an array:

client.query(
  q.ToArray({ name: 'Dennis', age: 37 })
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ [ 'name', 'Dennis' ], [ 'age', 37 ] ]
result = client.query(
  q.to_array({"name": "Dennis", "age": 37})
)
print(result)
[['name', 'Dennis'], ['age', 37]]
result, err := client.Query(
	f.ToArray(
		f.Obj{
			"name": "Dennis",
			"age": 37,
		}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[[age 37] [name Dennis]]
try
{
    Value result = await client.Query(
        ToArray(Obj("name", "Dennis", "age", 37))
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(Arr(StringV(name), StringV(Dennis)), Arr(StringV(age), LongV(37)))
System.out.println(
    client.query(
        ToArray(
            Obj("name", Value("Dennis"), "age", Value(37))
        )
    ).get());
[["name", "Dennis"], ["age", 37]]
ToArray({ name: 'Dennis', age: 37 })
[ [ 'name', 'Dennis' ], [ 'age', 37 ] ]
Query metrics:
  •    bytesIn:  50

  •   bytesOut:  43

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 1ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!