# Extracting Value using Javascript

**URL:** https://discourse.nodered.org/t/extracting-value-using-javascript/75724
**Category:** General
**Tags:** function-node, home-assistant
**Created:** [25 February 2023 10:10 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724 "2023-02-25T10:10:44Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![CJ10](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CJ10](https://discourse.nodered.org/u/CJ10)
#### Post date: [25 February 2023 10:10 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/1 "2023-02-25T10:10:44Z")

</div>

I have one object with multiple strings(?) which in turn have an associated value.

```auto

25/02/2023, 12:50:39[node: debug 4](http://homeassistant.local:8123/api/hassio_ingress/Es9h_91l3om-pMJ8ebe--nzrVZnJhDX5XNOIMrFJH48/#)

msg.payload : Object

object

buildNumber: "56633"

currentConfigNumber: 1

diversityMode: 3

unitMode: 1

```

I am using he following script to try to extract one of the values

```auto
msg.payload = msg.payload.licenseMask.value

return msg;

```

But I get an error

```auto
msg.payload : undefined

undefined

```

Can anyone direct me to the correct code to get the value?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [25 February 2023 10:24 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/2 "2023-02-25T10:24:53Z")

</div>

I don't see a property `licenseMask` in the example you posted.

---

<div class="post-metadata">

### Author: ![CJ10](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CJ10](https://discourse.nodered.org/u/CJ10)
#### Post date: [25 February 2023 10:32 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/3 "2023-02-25T10:32:37Z")

</div>

My apoologies, I missed it off;

```auto
25/02/2023, 13:31:54node: debug 4
msg.payload : Object
object
buildNumber: "56633"
currentConfigNumber: 1
diversityMode: 3
unitMode: 1
licenseMask: "128851337727"
configName: "Config 1"

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [25 February 2023 11:01 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/4 "2023-02-25T11:01:11Z")

</div>

`licenseMask` has not got a property `value`. You want  
`msg.payload = msg.payload.licenseMask`

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

### Author: ![CJ10](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CJ10](https://discourse.nodered.org/u/CJ10)
#### Post date: [26 February 2023 10:32 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/5 "2023-02-26T10:32:42Z")

</div>

Thanks Colin. I have read the page but for it just stops short of giving enough examples to make sense of. At least for someone with little experience like me.

So in the example on that page. I understand that the property is an object called msg.payload. But the bit I dont grasp is within that object, what are 'Firstname', 'Surname' and 'Age' referrred to as? Strings? And if 'Fred', 'Smith' and '28' are not values of those, what are they refered to as?

I am certain this is basic stuff for you guys but i'm clearly not understanding something very basic here.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [26 February 2023 11:36 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/6 "2023-02-26T11:36:22Z")

</div>

Using the example you posted at the start, then `licenseMask` is a property of the object msg.payload, just as `payload` is a property of the object msg. So msg.payload.licenseMask has the value "128851337727". The quotes tell you that the type of the property is String, without the quotes it would be a Number.

To answer your question, in the link I posted, "Fred" is the value of the property msg.payload.firstName. Think of msg.payload.firstName as a heirarchical address, like town.street.house, and "Fred" is the what is stored in the house.

Does that help?

---

<div class="post-metadata">

### Author: ![CJ10](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CJ10](https://discourse.nodered.org/u/CJ10)
#### Post date: [26 February 2023 11:51 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/7 "2023-02-26T11:51:50Z")

</div>

Yes, it does now I have reread your original comment.  
When you said;

> Blockquote  
> `licenseMask` has not got a property `value`  
> Blockquote

I was reading it as, LicenseMask does not have an associated value. But now I see you were saying there was no property called value in the object. Which is what I was mistakingly trying to do by using the code

```auto
msg.payload = msg.payload.licenseMask.value

```

Thanks that makes sense now.

> Blockquote

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 March 2023 11:52 UTC](https://discourse.nodered.org/t/extracting-value-using-javascript/75724/8 "2023-03-12T11:52:50Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
