使用Javascript: 我有两个数组。一个有关键的另一个有值..我需要将它们在键值对中合并到一个数组中。
arr2 = ["anik","manik","philip"];
arr1 =[1,2,3];
how to make
resultArray = ["anik:1","manik:2","philip:3"];
Array.prototype.associate = function (keys) {
var result = {};
this.forEach(function (el, i) {
result[keys[i]] = el;
});
return result;
};
var customerId = arr2;
var customerName = arr3;
console.log(customerId.associate(customerName));
console.log(Object.keys(arr));
//document.getElementById(customerId.associate(customerName));
array3 = [];
console.log(arr2);
arr2.forEach(function (e, i) {
array3.push(
[e] + ":" + arr3[i]
);
})
document.write(JSON.stringify(array3));