+1
Not a bug

accessing a string is returning an expected result

Roger [rocfusion] 9 years ago in iRidium Script updated by rocfusion 9 years ago 4
Hi,

Create a new project, add a new script, copy of the code below into the start listener and run the project. I would expect the output in the log to show that y variable is the character 's'. This script actually returns y as undefined.

var x= 'test';
IR.Log(typeof x); // returns a string
var y= x[2];
IR.Log(y);

Thanks,


Roger



Hi, Roger!
ECMA 3 is not support Bracket Notation for get a character of the string. Please use the charAt method.

var y = x.charAt(2);
IR.Log(y);

Hi Sergey,

Thanks, so we have moved to ECMA 3 now? When we change to a new ECMA script release can this be please noted in the change log?

BTW .... I have another workaround... you can also use..

var y= x.split('')[2];

this will also return the character at the specified position.

Thanks,


Roger