Javascript Data Type How to - Fill one array with another array by mapping








Question

We would like to know how to fill one array with another array by mapping.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--  www.  ja v  a  2 s.c o  m-->
var listOfFriends = [{"name" : "fName lName", "uid" : "0102030405"}, 
                     {"name" : "fName2 lName2", "uid" : "0504030201"}];
var listOfFriendsUIDs = listOfFriends.map(function (obj) { return obj.uid; });
document.writeln(listOfFriendsUIDs);

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

The code above is rendered as follows: