- Underscore.JS 教程
- Underscore.JS - 主页
- Underscore.JS - 概述
- Underscore.JS - 环境设置
- Underscore.JS - 迭代集合
- Underscore.JS - 处理集合
- Underscore.JS - 迭代数组
- Underscore.JS - 处理数组
- Underscore.JS - 函数
- Underscore.JS - 映射对象
- Underscore.JS - 更新对象
- Underscore.JS - 比较对象
- Underscore.JS - 实用工具
- Underscore.JS - 链式操作
- Underscore.JS 实用资源
- Underscore.JS - 快速指南
- Underscore.JS - 实用资源
- Underscore.JS - 讨论
Underscore.JS - zip method
语法
_.zip(*arrays)
zip 方法会合并数组中对应索引的值。
示例
var _ = require('underscore');
var list1 = ['Sam', 'Joe', 'Julie']
var list2 = [1, 2, 3]
var list3 = [true, false, true]
//Example 1: merge list1 and list2
result = _.zip(list1, list2);
console.log(result)
//Example 2: merge list1,list2 and list3
result = _.zip(list1, list2, list3);
console.log(result)
将上述程序保存到 **tester.js** 中。运行以下命令可执行此程序。
命令
\>node tester.js
输出
[ [ 'Sam', 1 ], [ 'Joe', 2 ], [ 'Julie', 3 ] ] [ [ 'Sam', 1, true ], [ 'Joe', 2, false ], [ 'Julie', 3, true ] ]
underscorejs_processing_array.htm
广告