# Extract a part of an object, convert to string and number

**URL:** <https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768>\
**Category:** Industrial\
**Tags:** function-node\
**Created:** [29 May 2023 02:38 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768 "2023-05-29T02:38:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wcordova](https://avatars.discourse-cdn.com/v4/letter/w/bb73d2/32.png) [@wcordova](https://discourse.nodered.org/u/wcordova)\
**Post date:** [29 May 2023 02:38 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/1 "2023-05-29T02:38:14Z")

</div>

Hi All  
I am using node red 3.0.3 and node js v18.16.0 in a raspberry pi. A flow storage (gravity sensor) in my program is generating an object with many fields. I want to know how can I get one of the fields ,this field should be number, so I guess that the field should be converted to a integer. How can I do that?  
This is the object structure (in fact has more fields), the only field that I need is called "minor"  
object  
uuid: "a495bb50c5b14b44b5121370f02d74de"  
major: 999  
minor: 1004  
tx\_power: -103  
rssi: -63  
mac: "c9:23:5f:60:d3:23"  
Color: "ORANGE"  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d92cab3a385300f9d746a24a3ea9afd3889029e.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a65becaa526116165ad377a1d9fe8763c97b6e6.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [29 May 2023 04:40 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/2 "2023-05-29T04:40:50Z")

</div>

Ok, not impossible.

But you need to post the data better.

Where you posted the message:  
Before pasting the code, click the `</>` button at the top (Or Control e)

```auto
type or paste code here

```

And paste the code/message where it says.

I'm guessing the part you want is `msg.minor`, but can not be sure.

Put a `function` node after the node that gives you the above message and basically you make it:

```auto
const msg.payload = parseInt(msg.minor);
return msg;

```

Then the next node gets a payload with an integer value which is what `msg.minor` was in the previous message.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 May 2023 06:46 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/3 "2023-05-29T06:46:19Z")

</div>

According to you image minor is already a number (shows blue in debug) If you hover your mouse over the minor name you will see three icons. One is copy path, If you copy it and paste it in a change node you can move the value where ever you wish.  
In a change node to move it to msg.payload  
set `msg` `payload`  
to value of `msg.` `payload.minor`

You may get some benefit from watching the  
[essentials videos](https://m.youtube.com/watch?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&v=ksGeUD26Mw0&embeds_referring_euri=https%3A%2F%2Fnodered.org%2F&source_ve_path=OTY3MTQ&feature=emb_imp_woyt)

---

<div class="post-metadata">

**Author:** ![wcordova](https://avatars.discourse-cdn.com/v4/letter/w/bb73d2/32.png) [@wcordova](https://discourse.nodered.org/u/wcordova)\
**Post date:** [30 May 2023 07:38 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/4 "2023-05-30T07:38:31Z")

</div>

Thanks a lot, it worked

```plaintext
var res = Number(str);
res=res*1000;
msg.payload = res;
return msg;

```

---

<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:** [30 May 2023 13:21 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/5 "2023-05-30T13:21:31Z")

</div>

In case you did not realise, you can shorten that to

```auto
msg.payload = Number(str)*1000
return msg

```

---

<div class="post-metadata">

**Author:** ![wcordova](https://avatars.discourse-cdn.com/v4/letter/w/bb73d2/32.png) [@wcordova](https://discourse.nodered.org/u/wcordova)\
**Post date:** [2 June 2023 03:56 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/6 "2023-06-02T03:56:57Z")

</div>

Thanks . it works

---

<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:** [1 August 2023 03:57 UTC](https://discourse.nodered.org/t/extract-a-part-of-an-object-convert-to-string-and-number/78768/7 "2023-08-01T03:57:29Z")

</div>

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