Typescript Index Last Element In Array Javascript Function