Answers for "negative indexing in arrays javascript"

0

negative indexing in arrays javascript

// javascript allows negative indexing but not same way as in python
const check = ["orange", "banana", "apple"]
// console.log(check[-1]) //returns an error
check[-1] = "negative fruit"
console.log(check) // ["orange", "banana", "apple", -1: "negative fruit"]
console.log(check[-1]) //returns "negative fruit"
// so it creates a key-value pair
Posted by: Guest on January-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language