Simply

 const obj = {};

 for (const key of yourArray) {
      obj[key] = whatever;
 }

or if you prefer "functional" style:

 const obj = yourArray.reduce((o, key) => Object.assign(o, {[key]: whatever}), {});

using the modern object spread operator:

const obj = yourArray.reduce((o, key) => ({ ...o, [key]: whatever}), {})

Example:

console.log(
[
  { id: 10, color: "red" },
  { id: 20, color: "blue" },
  { id: 30, color: "green" }
].reduce((acc, cur) => ({ ...acc, [cur.color]: cur.id }), {})
);

Here is how it works:

reduce is initialized with an empty object (empty {} at the end), therefore first iteration variables are acc = {} cur = { id: 10, color: "red" }. Function returns an object - this is why function body is wrapped in parentheses => ({ ... }). Spread operator doesn't do anything on the first iteration, so red: 10 is set as first item.

On the second iteration variables are acc = { red: 10 } cur = { id: 20, color: "blue" }. Here the spread operator expands acc and the function returns { red: 10, blue: 20 }.

Third iteration acc = { red: 10, blue: 20 } cur = { id: 30, color: "green" }, so when acc is spread inside the object, our function returns the final value.

Top answer
1 of 7
420

Simply

 const obj = {};

 for (const key of yourArray) {
      obj[key] = whatever;
 }

or if you prefer "functional" style:

 const obj = yourArray.reduce((o, key) => Object.assign(o, {[key]: whatever}), {});

using the modern object spread operator:

const obj = yourArray.reduce((o, key) => ({ ...o, [key]: whatever}), {})

Example:

console.log(
[
  { id: 10, color: "red" },
  { id: 20, color: "blue" },
  { id: 30, color: "green" }
].reduce((acc, cur) => ({ ...acc, [cur.color]: cur.id }), {})
);

Here is how it works:

reduce is initialized with an empty object (empty {} at the end), therefore first iteration variables are acc = {} cur = { id: 10, color: "red" }. Function returns an object - this is why function body is wrapped in parentheses => ({ ... }). Spread operator doesn't do anything on the first iteration, so red: 10 is set as first item.

On the second iteration variables are acc = { red: 10 } cur = { id: 20, color: "blue" }. Here the spread operator expands acc and the function returns { red: 10, blue: 20 }.

Third iteration acc = { red: 10, blue: 20 } cur = { id: 30, color: "green" }, so when acc is spread inside the object, our function returns the final value.

2 of 7
134

The new Object.fromEntries, from ECMAScript 2019, makes it even easier to transform values from an array into keys in an object like follows

const dynamicArray = ["2007", "2008", "2009", "2010"];
const obj = Object.fromEntries(
  dynamicArray.map(year => [year, {
    something: "based",
    on: year
  }])
)

console.log(obj)

Or maybe to solve your own original problem

const width = 1920
const height = 1080
const dynamicArray = ["2007", "2008", "2009", "2010"];
const obj = Object.fromEntries(
  dynamicArray.map((year, i) => [year, {
    x: (( i + 1) / 5) * width,
    y: height / 2
  }])
)

console.log(obj)

Discussions

javascript - Creating an array from object properties with Object.keys() vs Object.values() - Stack Overflow
Suppose I wanted to calculate the total sum of cats. I'll use reduce to calculate the sum of array values. But to create an array from the object above, I have two options: More on stackoverflow.com
๐ŸŒ stackoverflow.com
How might I extract the property values of a JavaScript object into an array? - Stack Overflow
Object.values() method is now supported. This will give you an array of values of an object. ... Refer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert an Object {} to an Array [] of key-value pairs in JavaScript - Stack Overflow
Finally (not part of the original ... or the value, but you don't want sparse arrays, no duplicates and no reordering without the need to convert to numeric keys (even can access very complex keys), then array (or object) is not what you need. I will recommend Map instead: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference... More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - How to obtain the object values from an array with one object and create a new array with just the object values - Stack Overflow
Array.prototype.values() method returns a new Array Iterator object that contains the values for each index in the array. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-create-array-of-objects-from-keys-values-of-another-object-in-javascript
How to Create Array of Objects From Keys & Values of Another Object in JavaScript ? - GeeksforGeeks
July 23, 2025 - Example: The below code uses Object.keys() and reduce() methods to create array of objects from keys and values of another object. ... const myObject = { key1: "HTML", key2: "CSS", key3: "JavaScript", }; const arrayOfObjects = Object.keys( myObject ...
๐ŸŒ
YouTube
youtube.com โ€บ dcode
Create arrays from objects with the Array.from() - JavaScript Tutorial - YouTube
In this video tutorial I'll be showing you how to use the Array.from() function in JavaScript which is super useful for creating new arrays from other iterab...
Published: November 6, 2019
Views: 2K
๐ŸŒ
Rip Tutorial
riptutorial.com โ€บ convert object's values to array
JavaScript Tutorial => Convert object's values to array
var array = Object.keys(obj) .map(function(key) { return obj[key]; }); console.log(array); // ["hello", "this is", "javascript!"]
Find elsewhere
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 76-converting-object-to-array
Converting Object to an Array | SamanthaMing.com
Array has an array of methods (sorry, bad pun ๐Ÿ˜). So by converting the object into an array, you have access to all of that. Woohoo ๐Ÿฅณ ยท const zoo = { lion: '๐Ÿฆ', panda: '๐Ÿผ', }; Object.keys(zoo); // ['lion', 'panda'] Object.values(zoo); // ['๐Ÿฆ', '๐Ÿผ'] Object.entries(zoo); // [ ['lion', '๐Ÿฆ'], ['panda', '๐Ÿผ'] ]
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-get-object-values-as-array
Convert an Object's Values or Keys to an Array in JavaScript | bobbyhadz
To get the values of an object as an array, use the `Object.values()` method, passing it the object as a parameter.
๐ŸŒ
YouTube
youtube.com โ€บ watch
JavaScript: Create a New Array By Extracting Object Values - YouTube
Arrays of objects can get complex, but we can simplify them by extracting only the object properties we need into a new array.For this example, I will use an...
Published: November 9, 2022
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ convert an object to an array in javascript
Convert an Object to an Array in JavaScript
March 29, 2020 - To convert an object to an array you use one of three methods: Object.keys(), Object.values(), and Object.entries().
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ how to create array of objects from an array
r/learnjavascript on Reddit: How to create array of objects from an array
May 20, 2022 -

Hello

How do I create an array of objects from an array?

My desired outcome is this:

const newArr = [
    { value: 'roman', label: 'Roman' },
    { value: 'thor', label: 'Thor' },
    { value: 'saige', label: ''Saige }
]

My starting array is this:

cosnt arr = ['Roman', 'Thor', 'Saige']

I believe I would use .map() but not doing it right. This is what I have:

let arr2 = arr.map(el => ({value: el.toLower(), label: el}))

Thanks!

๐ŸŒ
daily.dev
daily.dev โ€บ home โ€บ blog โ€บ webdev โ€บ js create array of objects: simplified
JS Create Array of Objects: Simplified | daily.dev
May 25, 2026 - Creating arrays of objects in JavaScript can seem complex at first, but it's a powerful way to organize and manage data. This guide simplifies the process, breaking it down into easy-to-understand steps. Here's what you'll learn: Basics Required: Understanding of variables, objects, arrays, loops, and functions. Creating an Array of Objects: How to declare an empty array and add object values to it.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Object โ€บ fromEntries
Object.fromEntries() - JavaScript - MDN Web Docs
October 30, 2025 - Typically, this object is implemented as a two-element array, with the first element being the property key and the second element being the property value. A new object whose properties are given by the entries of the iterable. The Object.fromEntries() method takes a list of key-value pairs ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-array-of-objects-tutorial-how-to-create-update-and-loop-through-objects-using-js-array-methods
JavaScript Array of Objects Tutorial โ€“ How to Create, Update, and Loop Through Objects Using JS Array Methods
May 14, 2020 - The Array.sort compares two objects and puts the first object in the second place if the result of the sorting function is positive. So you can look at the sorting function as if it was a question: Should the first object be placed in second place? Make sure to always add the case for zero when the compared value of both objects is the same to avoid unnecessary swaps.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ curriculum help
Create a new array with data from an object array - Curriculum Help - The freeCodeCamp Forum
June 7, 2022 - Can anyone tell me the best way to create a new array that contains data from another array that is created as an object. totalPts. = []; driver = []; driver[0] = new Object(); driver[0].pts = 12; driver[0].race_pts = 5; driver[1] = new Object(); ...