In JavaScript I have an array of three letter codes and I have a JSON file that has values for each of these codes. I need to map the codes to the corresponding values in the JSON file. Here's an example:
{"Roles" : [
{"code": "cmm", "fullname": "commentator"},
{"code": "cmp", "fullname": "composer"},
{"code": "cnd", "fullname": "conductor"},
{"code": "cng", "fullname": "cinematographer"},
{"code": "cns", "fullname": "censor"},
{"code": "com", "fullname": "compiler"}
]}
var arr = ["cmm", "com", "cng"];
var mappedArray = arr.map( ??? );
//mappedArray now contains: ["commentator", "composer", "cinematographer"]
I can't think of a way of solving this that isn't horribly inefficient. Can anyone help?
composerin your output? You meantcompiler, right?