# TypeError: Cannot read properties of undefined (reading 'includes')

**URL:** <https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786>\
**Category:** Developers\
**Created:** [November 6, 2022, 3:18pm UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786 "2022-11-06T15:18:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [November 6, 2022, 3:18pm UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786/1 "2022-11-06T15:18:51Z")

</div>

What am I doiing wrong, I keep getting this error

```auto
var ipAdres = '192.168.1.2';
var portNumber = '5005';
var radioPrefix = 'http://' + ipAdres + ':' + portNumber + '/woonkamer/favorite/';
var playListPrefix = 'http://'+ ipAdres + ':'+ portNumber + '/woonkamer/spotify/now/spotify:user:spotify:playlist:';
console.log('playListPrefix is: '+playListPrefix.length)

var radio = global.get('radio')
console.log('radio is: '+radio)
var playListId =global.get('playListId',playListId)
console.log('playListId is: '+playListId)
var playListName =global.get('playListName')
console.log('playListName is: '+playListName)

var tmpRadio = [0,0,0,0,0,0,0,0,0,0,0,0,0,0];

var count = 0
while(count <= radio.length )
{
if (radio[count].includes('http://192.168.1.2:5000/woonkamer/favorite/'))
{
tmpRadio.splice(count,1,radio[count].substring(((playListPrefix.length - 1)),radio[count].length - 1));

}
count++
}

```

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 6, 2022, 3:35pm UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786/2 "2022-11-06T15:35:06Z")

</div>

You’re using `includes` here:

```auto
radio[count].includes

```

The error says that `undefined` doesn’t have any properties (when it tries to access the property `includes`), so the conclusion is that `radio[count]` is undefined.

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [November 6, 2022, 3:54pm UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786/3 "2022-11-06T15:54:21Z")

</div>

When i run console.log(radio[0] it replies: [http://192.168.1.2:5005/woonkamer/favorite/Ibiza](http://192.168.1.2:5005/woonkamer/favorite/Ibiza) - HD  
So radio[0] exists, count = 0, so radio[count] must be the same?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 6, 2022, 6:43pm UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786/4 "2022-11-06T18:43:05Z")

</div>

It’s interesting that `radio[0]` contains a full string since `global.get()` returns a string and therefore `radio[0]` should only be the first character of that string.

The problem is likely the off-by-one counter in your loop (it should be `count < radio.length`).

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [November 6, 2022, 7:35pm UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786/5 "2022-11-06T19:35:06Z")

</div>

Ah what a stupid mistake. Thx. global. get(‘ radio’) gets an array. Every index is a string. Therefore radio[0] is a full string, as is radio[1] etc

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 7, 2022, 6:29am UTC](https://community.homey.app/t/typeerror-cannot-read-properties-of-undefined-reading-includes/71786/6 "2022-11-07T06:29:27Z")

</div>

Oh apologies for the confusion, I misread the documentation for `global.get()` and though it would always return a string 😅 But good to hear the problem is solved 👍🏻
