- I am just starting out with JavaScript.
- Everything works fine when I use an array for the health map method.
- However, when I try to use a single value, it throws an error: Uncaught TypeError: health.map is not a function
- Do you have any suggestions on how to fix this issue?
- Below is the code snippet:
Working Input:
let health =[{ "addedByName":"player", "mobileVersion":"sa,ple.txt" },
{ "addedByName":"player", "mobileVersion":"sa,ple.pdf" }
];
Not Working Input:
let health ={ "addedByName":"player", "mobileVersion":"sa,ple.txt" };
Fiddle with Code Example: http://jsfiddle.net/fq9ucpcb/
let health ={ "addedByName":"player", "mobileVersion":"sa,ple.txt" };
let types = ["text/plain", "application/pdf"];
let downloads = health.map(function(version) {
let ext = version.mobileVersion.replace(/.*(?=\.\w+)/, "");