# Accessing object properties in function

**URL:** <https://community.appfarm.io/t/accessing-object-properties-in-function/845>\
**Category:** Ask the community\
**Created:** [November 14, 2023, 4:46pm UTC](https://community.appfarm.io/t/accessing-object-properties-in-function/845 "2023-11-14T16:46:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![OleSorheim](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/olesorheim/32/1171_2.png) [@OleSorheim](https://community.appfarm.io/u/OleSorheim)\
**Post date:** [November 14, 2023, 4:46pm UTC](https://community.appfarm.io/t/accessing-object-properties-in-function/845/1 "2023-11-14T16:46:19Z")

</div>

Hi can someone explain what im doing wrong?

In the images below you can see my function and the console log. “unit” is loaded correctly (one array of length 1), and all the properties are there. However when i try to access the properties they are “undefined”.

![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/7443e5f826c779510ea1c8d2dd855a812612542c.png)  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/08d0b663e9d81b30be411bf5eac03bb54f18d817.png)

---

<div class="post-metadata">

**Author:** ![Lars](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/lars/32/67_2.png) [@Lars](https://community.appfarm.io/u/Lars)\
**Post date:** [November 14, 2023, 4:52pm UTC](https://community.appfarm.io/t/accessing-object-properties-in-function/845/2 "2023-11-14T16:52:53Z")

</div>

Hi!

As you mentioned, “unit” is an array. In this case, it’s an array with one object. To access this object, use: `unit[0]._id`.

I’m assuming that “unit” is a data source with cardinality “MANY,” indicating an array with potentially zero or more objects.

If the data source had cardinality “ONE,” it would be an object rather than an array, and your code would have worked.

Hope this helps!
