The simplest ES6 one-liner solution using Array reduce
:
const keys = ['height', 'width'];
const values = ['12px', '24px'];
const merged = keys.reduce((obj, key, index) => ({ ...obj, [key]: values[index] }), {});
More Related Contents:
- How Can i Change the style of my angularjs object?
- Convert JS object to JSON string
- Parse JSON String into a Particular Object Prototype in JavaScript
- Sum JavaScript object propertyA values with the same object propertyB in an array of objects
- Which characters are valid/invalid in a JSON key name?
- Convert object string to JSON
- How to get object length [duplicate]
- Sorting a JSON object in Javascript
- How to access nested JSON data
- Javascript group objects by property [closed]
- JSON.stringify function
- Reverse of JSON.stringify?
- How to write data to a JSON file using Javascript
- Encoding Javascript Object to Json string
- traversing through JSON string to inner levels using recursive function
- Is there any possibility to have JSON.stringify preserve functions?
- Multiple arguments vs. options object
- Push JSON Objects to array in localStorage
- What is the “right” JSON date format?
- How to get a subset of a javascript object’s properties
- How does the new operator work in JavaScript?
- Iterate through object properties
- Using number as “index” (JSON)
- jQuery: How to get the event object in an event handler function without passing it as an argument?
- How to escape a JSON string to have it in a URL?
- JSON security best practices?
- How to deterministically verify that a JSON object hasn’t been modified?
- Writing a json object to a text file in javascript
- Returning JSON array from a Django view to a template
- Get the property of the difference between two objects in javascript