ToObject

Not available in this language yet.
ToObject( array )
ToObject( array )
ToObject( array )
to_object( array )
ToObject( array )

Description

The ToObject function converts an Array of arrays, containing field names and values, into an Object, if possible.

If array cannot be converted into an object, an "invalid argument" error is returned.

Parameters

Argument Type Definition and Requirements

array

An array of arrays containing field names and values.

Returns

An object composed of the fields names and values from array.

Examples

The following query converts an array into an object:

Not available in this language yet.
result, err := client.Query(
	f.ToObject(
		f.Arr{
			f.Arr{"name", "Dennis"},
			f.Arr{"age", 37},
		}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[age:37 name:Dennis]
System.out.println(
    client.query(
        ToObject(
            Arr(
                Arr(Value("name"), Value("Dennis")),
                Arr(Value("age"), Value(37))
            )
        )
    ).get());
{name: "Dennis", age: 37}
client.query(
  q.ToObject([['name', 'Dennis'], ['age', 37]])
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{ name: 'Dennis', age: 37 }
result = client.query(
  q.to_object([['name', 'Dennis'], ['age', 37]])
)
print(result)
{'name': 'Dennis', 'age': 37}
println(Await.result(
  client.query(
    ToObject(
      Arr(
        Arr("name", "Dennis"),
        Arr("age", 37)
      )
    )
  ),
  5.seconds
))
{name: "Dennis", age: 37}

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!