I have two arrays like so:
arr1 = ['one','two','three']
arr2 = ['1','2','3']
Is there a way with jQuery to combine them so the output would be like:
arr3 = ['one':'1', 'two':'2', 'three':'3']
I believe you are asking to create an object (associative array) if so
var arr1 = ['one','two','three'];
var arr2 = ['1','2','3'];
var combo_obj = {};
arr1.forEach(function(element, index) {
combo_obj[element] = arr2[index];
});
console.log(combo_obj);
here is its output
{ one: '1', two: '2', three: '3' }
Yes. Check here: Combaining two array into single multi dimensional array in javascript
Here is an example:
arr3=[];
for (i = 0; i < arr2.length; ++i)
{
arr3[i] = Array(arr1[i], arr2[i]);
}
{ key: value }[[k1,v1],[k2,v2],..]or even["k1:v1","k2:v2",..]or..?