Javascript Array Negative Indexing In R