Hammer
09 Sep 2022Consider these two Typescript snippets:
// specimen 1
const KEY_VALUE = {
'prop-key-1': 'some-prop-value-1',
'prop-key-2': 'some-prop-value-2'
};
Object.keys(KEY_VALUE).forEach(key => {
// do something with key and KEY_VALUE[key];
});
// specimen 2
interface KeyValue {
key: string;
value: string;
}
const KEY_VALUE: KeyValue[] = [
{
key: 'prop-key-1',
value: 'some-prop-value-1',
},
{
key: 'prop-key-2',
value: 'some-prope-vale-2'
}
];
KEY_VALUE.forEach(pair => {
// do something with pair.key and pair.value
});
Which approach would you rather implement in your project? And why?