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

JavascriptObject Oriented ProgrammingFront End Technology

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',
}
raja
Updated on 23-Jun-2020 13:21:48

Advertisements