# Can somebody help me extract this object which start with a number?

**URL:** <https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956>\
**Category:** General\
**Created:** [24 February 2022 21:47 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956 "2022-02-24T21:47:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [24 February 2022 21:47 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/1 "2022-02-24T21:47:21Z")

</div>

Hi, I've just discovered that unfortunately Openweather returns on hourly data an object instead of the simple value (as for daily), please look here:

 ![immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61f8b266aecb2cb489d805e3f359c28dbc1d4c83.png)

I try to exttract this number in this way

```auto
var precipitazioni = [];
for (let i = 0; i < 25; i++) { 
	precipitazioni[i]=0;
	if (typeof msg.payload.hourly[i].snow.1h!== 'undefined' {precipitazioni[i]=msg.payload.hourly[i].snow.1h;}
	if (typeof msg.payload.hourly[i].rain.1h!== 'undefined') {precipitazioni[i]=msg.payload.hourly[i].rain.1h;}}

```

unfortunately seams the number 1 creates problems on node red syntax checker, how can I overcome that? Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 February 2022 21:57 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/2 "2022-02-24T21:57:10Z")

</div>

To avoid typos, use the tools provided. Use the "Copy Path" button in the debug sidebar.

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)

* * *

PS, for reference, for accessing non standard object properties you use [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#bracket_notation)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 February 2022 22:01 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/3 "2022-02-24T22:01:26Z")

</div>

As well as any hints that Steve has given you, your first if() statement is missing it's )

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [24 February 2022 22:31 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/4 "2022-02-24T22:31:45Z")

</div>

Thanks!  
I've follower your guide, it' looks like I've to type msg.payload.hourly[i].snow["1h"], but using this code:

```auto
var precipitazioni = [];
var massimo=0;
for (let i = 0; i < 25; i++) { 
	precipitazioni[i]=0;
	if (typeof msg.payload.hourly[i].snow["1h"]!== 'undefined') {precipitazioni[i]=msg.payload.hourly[i].snow["1h"];}
	if (typeof msg.payload.hourly[i].rain["1h"]!== 'undefined') {precipitazioni[i]=msg.payload.hourly[i].rain["1h"];}
	if (precipitazioni[i]>massimo) {massimo=precipitazioni[i];}
	massimo=Math.round(massimo*10) /10;
	}

```

I have the error:  
"TypeError: Cannot read property '1h' of undefined"  
that's strange, looks a syntax error, if this property doesn't exist it simply has to ignore it, but not. Hw can I fix it?

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [24 February 2022 22:37 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/5 "2022-02-24T22:37:11Z")

</div>

I overcomed the error with a double check, but I still have all zeros as output, so this ["1h"] doesn't catch the value

```auto
var precipitazioni = [];
var massimo=0;
for (let i = 0; i < 25; i++) { 
	precipitazioni[i]=0;
	if (typeof msg.payload.hourly[i].snow!== 'undefined') {
		if (typeof msg.payload.hourly[i].snow["1h"]!== 'undefined'){precipitazioni[i]=msg.payload.hourly[i].snow["1h"];}}
	if (typeof msg.payload.hourly[i].rain!== 'undefined') {
	if (typeof msg.payload.hourly[i].rain["1h"]!== 'undefined') {precipitazioni[i]=msg.payload.hourly[i].rain["1h"];}}
	if (precipitazioni[i]>massimo) {massimo=precipitazioni[i];}
	massimo=Math.round(massimo*10) /10;
	}

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 February 2022 23:00 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/6 "2022-02-24T23:00:03Z")

</div>

This is my code processing the precipitation data from OWM, it's a different test for the existence of rain and snow quantities. I'm only looking for values greater than 1mm.

```auto
msg.payload.hourly.forEach(element => {
if (element.hasOwnProperty('rain')&&element.rain["1h"]>1) {element.rainmm = Math.round(element.rain["1h"]) + "mm";}
if (element.hasOwnProperty('snow')&&element.snow["1h"]>1) {element.snowmm = Math.round(element.snow["1h"]) + "mm";}
}

```

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [24 February 2022 23:02 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/7 "2022-02-24T23:02:02Z")

</div>

Thanks, it works, also my code, I've just missed a the only value available (I?m checking every 2 hours, it happened at 3rd hour so I didn't see it.  
Good!

---

<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:** [10 March 2022 23:02 UTC](https://discourse.nodered.org/t/can-somebody-help-me-extract-this-object-which-start-with-a-number/58956/8 "2022-03-10T23:02:51Z")

</div>

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