Javascript Data Type How to - Populate an array from another array and modify values by using map function








Question

We would like to know how to populate an array from another array and modify values by using map function.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from w  ww .  j  a v  a  2  s .  c  o m-->
var singularArray = ['Dog', 'Cat', 'Bird'],
    pluralArray = singularArray.map(function(value){
        return value+'s';
    });
document.writeln(pluralArray);
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: