I have the following dictionary:
{1:['a&b','b-c','c-d'],2:['e orf ','f-k-p','g']}
I want to print the key and values from this dictionary I tried the following code:
for (var key in dictionary) {
// check if the property/key is defined in the object itself, not in parent
if (dictionary.hasOwnProperty(key)) {
console.log(key, dictionary[key]);
}
}
I am just getting some random numbers.How could I solve it? My output:
key:34639values:mkey:34640values:akey:34641values:tkey:34642values:hkey:34643values:ekey:34644values:mkey:34645values:akey:34646values:tkey:34647values:ikey:34648values:ckey:34649values:skey:34650values: key:34651values:pkey:34652values:rkey:34653values:okey:34654values:bkey:34655values:lkey:34656values:ekey:34657values:mkey:34658values:
I want the output as:
keys: 1,2
values: ['a&b','b-c','c-d'],['e orf ','f-k-p','g']
var dictionary = {1:['a','b','c'],2:['e','f','g']}
for (var key in dictionary) {
// check if the property/key is defined in the object itself, not in parent
if (dictionary.hasOwnProperty(key)) {
console.log(`key: `, key);
console.log(`values: `, dictionary[key]);
}
}
Edit: Actually the dictionary is taken as string. How can I typecast it to dictionary?