Don’t use an array if you want named keys, use a plain object.
var a = {};
a["key1"] = "value1";
a["key2"] = "value2";
Then:
if ("key1" in a) {
// something
} else {
// something else
}
More Related Contents:
- React Javascript Array Object [closed]
- How can I access field 1 value from this dictionary by using java script?
- Map vs Object in JavaScript
- How do you JSON.stringify an ES6 Map?
- How to do associative array/hashing in JavaScript
- How to concatenate properties from multiple JavaScript objects
- Performance of key lookup in JavaScript object
- Why is Proxy to a Map object in ES2015 not working
- How to iterate (keys, values) in JavaScript? [duplicate]
- How do I persist a ES6 Map in localstorage (or elsewhere)?
- Using Array objects as key for ES6 Map
- How to reliably check an object is an EcmaScript 6 Map/Set?
- How to create dictionary and add key–value pairs dynamically?
- Define a custom hash() method for use with ES6 maps
- JavaScript – Map() increment value
- Main difference between map and reduce
- How to create dictionary and add key value pairs dynamically in Javascript
- map function not working in React
- First item from a Map on JavaScript ES2015
- Using array map to filter results with if conditional
- Sort a dictionary by value in JavaScript
- Maximum number of entries in Node.js Map?
- Why does a js map on an array modify the original array?
- How can I get a key in a JavaScript ‘Map’ by its value?
- How do I interpolate a variable as a key in a JavaScript object?
- How can I check if two Map objects are equal?
- Displaying Javascript variables in HTML
- How do I copy to the clipboard in JavaScript?
- How to tell if a tag failed to load
- getElementsByName() not working? [duplicate]