negative indexing in arrays javascript

Solutions on MaxInterview for negative indexing in arrays javascript by the best coders in the world

showing results for - "negative indexing in arrays javascript"
Paulina
27 Jul 2018
1// javascript allows negative indexing but not same way as in python
2const check = ["orange", "banana", "apple"]
3// console.log(check[-1]) //returns an error
4check[-1] = "negative fruit"
5console.log(check) // ["orange", "banana", "apple", -1: "negative fruit"]
6console.log(check[-1]) //returns "negative fruit"
7// so it creates a key-value pair
similar questions
queries leading to this page
negative indexing in arrays javascript