Javascript: Generic get next item in array

You’ve almost got it right, but the syntax is arr[x], not arr(x):

index = array.indexOf(value);
if(index >= 0 && index < array.length - 1)
   nextItem = array[index + 1]

BTW, using an object instead of an array might be a better option:

data = {"ball":"1f7g", "spoon":"2c8d", "pen":"9c3c"}

and then simply

code = data[name]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)