# Question about Observable Arrays in JS

**URL:** <https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850>\
**Category:** How-to Discussions\
**Created:** [March 23, 2017, 6:22am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850 "2017-03-23T06:22:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferdinand.berthelsen](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@ferdinand.berthelsen](https://forums.fusetools.com/u/ferdinand.berthelsen)\
**Post date:** [March 23, 2017, 6:22am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/1 "2017-03-23T06:22:19Z")

</div>

I have difficulties with Observable arrays when trying to get to the variables inside them in JS. In UX I know that the variables of `Human = Observable({firstname: "Charlie", lastname: "Kelly"})` is referenced by `Value="{Human.firstname}"`. But this does not seem to apply to the JS practice as it returns Undefined (`console.log("First name: " + Human.firstname)`). I’ve tried using `Human.toArray()` which doen’t seem to do anything other than just make an exact copy. I’ve also tried to access the values with `Human._values.firstname` wihtout any luck. There’s no specific mention of this in neither the quick documentation about Observables or the Observable API.

What is the proper practice for accessing these values in an Observable array in JS?  
Please help.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Remi\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/remi_pedersen/32/432_2.png) [@Remi\_Pedersen](https://forums.fusetools.com/u/Remi_Pedersen)\
**Post date:** [March 23, 2017, 10:03am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/2 "2017-03-23T10:03:13Z")

</div>

In the example you mention there’s no list as the observable holds just 1 value. In that case you’d just access it as `console.log("First name: " + Human.value.firstname)`  
This is documented at the top of the [Observable API docs](https://www.fusetools.com/docs/fusejs/observable-api#observable-value)

Another important thing to keep in mind is that observables are _lists_ and therefore can’t be accessed as arrays.  
To manipulate elements in these lists you can use the [observable list api](https://www.fusetools.com/docs/fusejs/observable-api#list-operators)

---

<div class="post-metadata">

**Author:** ![ferdinand.berthelsen](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@ferdinand.berthelsen](https://forums.fusetools.com/u/ferdinand.berthelsen)\
**Post date:** [March 24, 2017, 7:18am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/3 "2017-03-24T07:18:24Z")

</div>

Thank you for the reply!  
I have used JSON arrays in JS by doing Thing.something so I just assumed that Observable.value would return Undefined as Human does not have an element called “value”. But thanks for the pointers!

---

<div class="post-metadata">

**Author:** ![ferdinand.berthelsen](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@ferdinand.berthelsen](https://forums.fusetools.com/u/ferdinand.berthelsen)\
**Post date:** [March 24, 2017, 7:40am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/4 "2017-03-24T07:40:23Z")

</div>

Hmmm still doesn’t seem to assign properly…

if i try `console.log(Happening.value.title);` it prints `undefined`.

---

<div class="post-metadata">

**Author:** ![Remi\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/remi_pedersen/32/432_2.png) [@Remi\_Pedersen](https://forums.fusetools.com/u/Remi_Pedersen)\
**Post date:** [March 24, 2017, 8:56am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/5 "2017-03-24T08:56:58Z")

</div>

Impossible to comment on that based on just that line. 🙂  
If you want help then please provide more of the relevant code so we can see how `Happening` is set up.

---

<div class="post-metadata">

**Author:** ![ferdinand.berthelsen](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@ferdinand.berthelsen](https://forums.fusetools.com/u/ferdinand.berthelsen)\
**Post date:** [March 28, 2017, 3:53am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/6 "2017-03-28T03:53:17Z")

</div>

Oh sorry, I tried to avoid it since it’s a bit complicated but hang in there!

```
Happening = Observable();
...

    this.Parameter.onValueChanged(module, function(param) {

	IsHost.value = param.isHost;
	console.log("IsHost.value: " + IsHost.value);

	UserContext.getStorageUser().then(function(user_result) {

		HappeningContext.getHappenings(param.eventId, user_result.id).then(function(happenings_result) {

			if (happenings_result !== false) {

				Happenings.replaceAll(happenings_result);
				NoHappenings.value = false;
			}

			Loading.value = false;
		});
	});

});

...

 function save() {

	console.log("Happening.value.title: " + Happening.value.title);

	var happeningObject = {

		id: Happening.value.id,
		event_id: Happening.value.event_id,
		title: Happening.value.title,
		text: Happening.value.text,
		from: Happening.value.from,
		to: Happening.value.to
	};

	happeningsRouter.goto("savingHappening");

	if (FormMode.value == "add") {

		// HappeningContext.add(happeningObject).then(function(result){

		// console.log("result: " + result);
		// });

	} else if (FormMode.value == "edit") {

		HappeningContext.set(happeningObject).then(function(result){

			console.log("result: " + result);
		});

	}
}

```

Happening anatomy

- [Attached JSON file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/CCsYzu74UHiR-image-1490673173590.json)

---

<div class="post-metadata">

**Author:** ![Remi\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/remi_pedersen/32/432_2.png) [@Remi\_Pedersen](https://forums.fusetools.com/u/Remi_Pedersen)\
**Post date:** [March 28, 2017, 7:29am UTC](https://forums.fusetools.com/t/question-about-observable-arrays-in-js/4850/7 "2017-03-28T07:29:32Z")

</div>

I can’t see anything in that code which actually assigns any value to `Happening` (just to Happening_s_)
