Objects and Extraction of Key-Value Pairs
Sun Dec 12 2021 10:15:06 GMT+0000 (Coordinated Universal Time)
Saved by
@vincentleoooo
#javascript
var positions = {
arrivals: 0,
immigration: 0,
testing: 0,
baggage: 0,
exiting: 5,
undefined: 0,
};
var objects = {
immigration: [],
immigrationQueue: [],
passengers: [],
testing: [],
testingBox: [],
testingQueue: [],
baggage: [],
baggageQueue: [],
};
// Get the key of a certain value by going through
// the whole object.
function getKeyByValue(object, value) {
return Object.keys(object).find((key) => object[key] === value);
}
// How to access values through keys
objects.immigration == []; // true
let newString = immigration;
objects[newString] == []; // true
content_copyCOPY
Comments