数组方法: associate
创建一个基于传入数组和数组内容的键值对对象。传入数组为键,原数组对象为值(键值对对象)。
语法:
var associated = myArray.associate(key);
参数:
- key - (array) 数组的项将被用于生成对象的键。
返回:
- (object) 生成的键值对对象。
举例:
var animals = ['Cow', 'Pig', 'Dog', 'Cat'];
var sounds = ['Moo', 'Oink', 'Woof', 'Miao'];
sounds.associate(animals); // 返回{'Cow': 'Moo', 'Pig': 'Oink', 'Dog': 'Woof', 'Cat': 'Miao'}