Associative arrays in Javascript
· ☕ 1 min read
tldr; There are no associative arrays in Javascript. But there is indeed a credible alternative.
In PHP, we can do the following -
1 2 3 4 var fruits={}; fruits[3]="apple"; fruits[2]="orange"; fruits[1]="pear"; Javascript does not have associative arrays.
All you can do is -
1 const fruits = ["apple", "orange", "pear"]; Yes, you can define props for the array itself, but that is an altogether different thing.