What am I doiing wrong, I keep getting this error
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++
}
You’re using includes
here:
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.
When i run console.log(radio[0] it replies: http://192.168.1.2:5005/woonkamer/favorite/Ibiza - HD
So radio[0] exists, count = 0, so radio[count] must be the same?
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
).
1 Like
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
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 