javascript - First element in array -


why indexes in arrays start 0? have binary? example:

var myarray = [5,6,7,8]; 

to access number 5, have

myarray[0] 

but why?

no, don't have real problem. can evidently tell i'm new stuff.

i'm sure has been asked answered hundred times, i'll bite.

one way of looking @ "index" or "key" "offset".

myarray acts pointer first item in series of items. specifically, points number "5" in memory. when myarray[1] it's saying "the location of first element in myarray plus 1 item over", jumping on first element.

in c, when write *myarray (pointer dereference) gives first element.

#include <stdio.h>  int main(void) {     int myarray[] = {5,6,7,8};     printf("%d",*myarray); // prints "5", equivalent myarray[0]     printf("%d",*(myarray+1)); // prints "6", equivalent myarray[1]     return 0; } 

there more practical reasons "that's way computers work" too.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -