I have a javascript object which looks like
dict1 = {"key1":"value1",
"key2":"value2",
"key3":"value3",
"key4":"value4",
"key5":"value5"}
Next I have got an array which is arr1 = ["key1","key2"]
All I need to do is fetch the value from dict1 based elements in the array and concat them as string.
Sounds fairly Simple:
dict1[arr1[0]] + '-' + dict1[arr1[1]]
Output :
value1-value2
The tricky part for me is that the array arr1 can be of any length but is always the subset of keys present in dict1. For ex:
arr1= ["key2","key5"]
arr1= ["key1","key5","key3"]
arr1= ["key4"]
Based on these input following output is expected:
value2-value5
value1-value5-value3
value4
I am having trouble writing a generic script to create the string dynamically
arr1.map(key=>dict1[key]).join("-")?