In your example: "data" is a Snap list object, not an array. Snap lists have a method named
length is true-ish (another problematic concept in JS, just sayin'), you believe that the result tells you whether the list has zero (false) or more (true) elements. But, since data is a Snap list it only tells you whether that objects has a property named
length whose value is not null and not undefined. Since there is a method named
length the result is always true. In order to get what you think you're getting you'd have to call length() instead. However, you're making it even worse by assigning the method (!) named "length" to the variable named "i_end" and by using that inside both a conditional and a for-loop, mistakingly assuming it's a number when it really is a function.
See, this is hard, and you didn't even learn anything, at least nothing that's even remotely interesting, or anything that will make you a better programmer. This is exactly why I strongly discourage such discussions about JS and Snap here. I know folks lap it up. They're overly eager to learn the "secrets" behind Snap. And I'm not keeping any secrets closed, by golly, it's all open. But one reason we're having it all open for everybody to see is that we don't have to talk about it here.
Now, since you're an aspiring JS programmer you've learned that
slice() copies an array. But you didn't realize that a list isn't an array and does not have a method named slice, same story. Is this really a topic that's interesting in this forum? Do you think kids - or teachers - learn something worthwhile from such a question?