Can only check to last elemnt in array. Index is zero based, so last index is ( length - 1)
Change to just less than length
for(x = 0; x < path.length; x=x+2)
You are overshooting the array in your code, so last pass will return undefined for path[x]