Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
Object.fromEntries()
Examples
Basic example
// Array containing the name and stock quantity
// of various products.
let products = [
[
"bananas",
300
],
[
"limes",
200
],
[
"lemons",
500
]
]
// Convert the Array to an Object.
Object.fromEntries(products)
{
bananas: 300,
limes: 200,
lemons: 500
}
Transform Objects
You can use Object.entries()
,
Object.fromEntries()
, and
Array methods to transform
objects:
// This query multiplies each Number in an Object
// by 2.
// An object containing various Numbers.
let nums = {
a: 1,
b: 2,
c: 3
}
// Convert the Array to an Object.
let numArray = Object.entries(nums)
// Iterate through the Array, multiplying
// each value and outputting an Object.
Object.fromEntries(
numArray.map(elem => {
let key = elem[0]
let value = elem[1]
[ key, value * 2 ]
})
);
{
a: 2,
b: 4,
c: 6
}
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!