I have a dynamically generated large string which I am splitting.
var myString="val1, val, val3, val4..... val400"
I do a simple split on this string,
myString= myString.split(',')
getting the following:
myString[1] // gives val1
myString[2] // gives val2
myString[3] // gives val3
.
.
.
myString[400] // gives val400
Is there a way to make the following?
myString[101] // gives val1
myString[102] // gives val2
myString[103] // gives val3
.
.
.
myString[500] // gives val400
Arrays are zero-based, so in fact in your version you have indices 0 up to 399 rather than 1 to 400.
I’m not quite sure why you’d want 100 items padding out the start of the array, but for what it’s worth, here’s a short way of doing what you want. It’s also one of the few times the
Arrayconstructor is actually useful: