Javascript Data Type How to - Map array to another array








Question

We would like to know how to map array to another array.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from w w w.  java2  s  .c om-->
var potentialmodels = {
    "maddiekeller": {
        "firstname":"Maddie",
        "lastname":"Keller"
        },
    "rickbross": {
        "firstname":"Rick",
        "lastname":"Bross"
    }
}
var nameArray = Object.keys(potentialmodels).map(function(model) { 
   return potentialmodels[model].firstname 
});
document.writeln(nameArray);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: