How to workaround Objects vs arrays in JavaScript for key/value pairs?


Store it like the following −

var players = {
   600 : 'Sachin',
   300 : 'Brad',
};

For key/ value pairs, we have used the above solution, since we wanted a one-to-one. We did this to use the key as a lookup key. You can also add more values like this −

var players = {
   900 : 'Sachin',
   300 : 'Brad',
   700 : 'Steve',
   200 : 'Rahul',
   600 : 'Kevin',
   500 : 'David',
}

Updated on: 23-Jun-2020

111 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements