OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Create an object from an array of keys and an array of values

  • Thread starter Thread starter user6535476
  • Start date Start date
U

user6535476

Guest
I have two arrays: newParamArr and paramVal.

Example values in the newParamArr array: [ "Name", "Age", "Email" ].

Example values in the paramVal array: [ "Jon", 15, "[email protected]" ].

I need to create a JavaScript object that places all of the items in the array in the same object. For example { [newParamArr[0]]: paramVal[0], [newParamArr[1]]: paramVal[1], ... }.

In this case, the result should be { Name: "Jon", "Age": 15, "Email": "[email protected]" }.

The lengths of the two arrays are always the same, but the length of arrays can increase or decrease. That means newParamArr.length === paramVal.length will always hold.

None of the below posts could help to answer my question:

Javascript Recursion for creating a JSON object

Recursively looping through an object to build a property list

<p>I have two arrays: <code>newParamArr</code> and <code>paramVal</code>.</p>
<p>Example values in the <code>newParamArr</code> array: <code>[ "Name", "Age", "Email" ]</code>.</p>
<p>Example values in the <code>paramVal</code> array: <code>[ "Jon", 15, "[email protected]" ]</code>.</p>
<p>I need to create a JavaScript object that places all of the items in the array in the same object. For example <code>{ [newParamArr[0]]: paramVal[0], [newParamArr[1]]: paramVal[1], ... }</code>.</p>
<p>In this case, the result should be <code>{ Name: "Jon", "Age": 15, "Email": "[email protected]" }</code>.</p>
<p>The lengths of the two arrays are always the same, but the length of arrays can increase or decrease. That means <code>newParamArr.length === paramVal.length</code> will always hold.</p>
<p>None of the below posts could help to answer my question:</p>
<p><a href="https://stackoverflow.com/questions/11827456/javascript-recursion-for-creating-a-json-object">Javascript Recursion for creating a JSON object</a></p>
<p><a href="https://stackoverflow.com/questions...ng-through-an-object-to-build-a-property-list">Recursively looping through an object to build a property list</a></p>
 
Top