

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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', }
- Related Questions & Answers
- JavaScript: How to Create an Object from Key-Value Pairs
- How to Sort object of objects by its key value JavaScript
- How to add key/value pairs in SortedList in C#?
- Arrays vs Set in JavaScript.
- Find specific key value in array of objects using JavaScript
- How to loop through arrays in JavaScript objects?
- Merge JavaScript objects with the same key value and count them
- How to extract subset of key-value pairs from Python dictionary object?
- Join two objects by key in JavaScript
- Group all the objects together having the same value for the '_id' key in JavaScript
- Primary key Vs Unique key
- How to group an array of objects by key in JavaScript
- How to convert nested array pairs to objects in an array in JavaScript ?
- How to merge two arrays with objects in one in JavaScript?
- Create a TreeMap in Java and add key-value pairs
Advertisements