建立一個通過 iteratee
處理的集合中每個元素的結果數組。 iteratee 會傳入3個參數:(value, index|key, collection)。 javascript
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>map</title>
</head>
<body>
<script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script>
<script type="text/javascript">
function square(n) { return n * n; } console.log(_.map([4, 8], square)); //[16,64]
var users = [{ 'user': 'barney' }, { 'user': 'fred' } ]; console.log(_.map(users, 'user')); //['barney','fred']
</script>
</body>
</html>