How to turn an array into an object with two values? javascript -


i want put array object 2 keys (key, val). code.

var arr = ["hello", "44", "thanks", "32"];  console.log(arr); console.log(arr.length);  var obj = {};  (var = 0; < arr.length; i++) {     obj.key = arr[i]; }  console.log(obj); 

this result have.

obj[0] = {key: "hello", val: "44"};  obj[1] = {key: "thanks", val: "32"};  

thanks allot!

so, want loop every 2 item instead of 1, , take current item , next one.

maybe :

obj = []; (var = 0; < arr.length; i=i+2) {   obj.push({key:arr[i], val:arr[i+1]}); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -