Sign In Register

How can we help you today?

Start a new topic

lastIndexOf Bug

 Hi there,

var str = "Hello planet earth, you are a great planet.";
var n = str.lastIndexOf("planet", 0); 
Spark.setScriptData("idx", n);

idx returns -1, only when I set the from parameter in lastIndexOf.

1 Comment

Thats the way lastIndexOf works... The second parameter is an index from the end backwards, so you are looking for "planet" at the end of the string (-1 means it was not found)

If you omit the start param, then it default to the length of the string (in this case 43) so if you supply 43 it should start to make sense.

Login to post a comment