You can use Object.keys() and map() to do this

var obj = {"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
var result = Object.keys(obj).map((key) => [key, obj[key]]);

console.log(result);

Answer from Nenad Vracar on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
A new Array instance. ... To convert an ordinary object that's not iterable or array-like to an array (by enumerating its property keys, values, or both), use Object.keys(), Object.values(), or Object.entries().
Discussions

javascript - How to convert an array into an object? - Stack Overflow
What is the best way to convert: ['a','b','c'] to: { 0: 'a', 1: 'b', 2: 'c' } More on stackoverflow.com
🌐 stackoverflow.com
How to go from object to array and back again
I’m curious at to where or when this would be useful. Somewhat of a newer dev so this may just be going over my head. More on reddit.com
🌐 r/learnjavascript
10
207
January 17, 2023
How to transform an array of numbers into objects?
I think you've got it, just need to return your map. IE: return numberArray.map(... More on reddit.com
🌐 r/learnjavascript
19
14
February 3, 2023
Convert array to object
Hello, Thanks in advance for the help, I’m currently a student developer and really having a hard time with my assignments. Here is the most recent and its simply converting an array into an object. I there is someone that wouldn’t mind be a mentor that would be extremely helpful. function ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
February 22, 2021
🌐
Medium
medium.com › dailyjs › converting-object-to-an-array-in-javascript-c7147f2ff750
Converting Object to an Array in JavaScript | by Samantha Ming | DailyJS | Medium
November 4, 2019 - Okay, I’m exaggerating a bit 😅. But I remember whenever I needed to convert an object into an array, I had to do something like this. var numbers = { one: 1, two: 2 };var keys = [];for (var number in numbers) { if(numbers.hasOwnProperty(number)){ keys.push(number) } }keys; // [ 'one', 'two' ] I always was so angry and wished there was a better way… · And then ES6 happened! My life changed! We finally have an easier way 🥳 ... JavaScript news and opinion.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-an-object-into-array-of-objects-in-javascript
How to Convert an Object into Array of Objects in JavaScript? - GeeksforGeeks
July 23, 2025 - Here are the different methods to convert an object into an array of objects in JavaScript · Object.values() method extracts the property values of an object and returns them as an array, converting the original object into an array of objects.
🌐
Reddit
reddit.com › r/learnjavascript › how to go from object to array and back again
r/learnjavascript on Reddit: How to go from object to array and back again
January 17, 2023 - I think it’s important to note that the original object still exists. Object.entries() returns a new array, so you can continue to use the original.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › fromEntries
Object.fromEntries() - JavaScript | MDN
October 30, 2025 - With Object.fromEntries, its reverse method Object.entries(), and array manipulation methods, you are able to transform objects like this: ... const object1 = { a: 1, b: 2, c: 3 }; const object2 = Object.fromEntries( Object.entries(object1).map(([key, val]) => [key, val * 2]), ); ...
🌐
ServiceNow Community
servicenow.com › community › developer-forum › please-suggest-how-to-convert-object-to-array-in-javascript › m-p › 2657108
Please suggest how to convert object to array in javascript
August 30, 2023 - To convert an ordinary object that's not iterable or array-like to an array (by enumerating its property keys, values, or both), use Object.keys() , Object.values() , or Object.entries() . To convert an async iterable to an array, use Array.fromAsync() .
🌐
ConvertCSV
convertcsv.com › json-to-csv.htm
JSON To CSV Converter
THIS CONVERSION is NOW AVAILABLE as an API at ConvertCsv.io · Your JSON input should contain an array of objects consistings of name/value pairs. It can also be a single object of name/value pairs or a single object with a single property with an array of name/value pairs. It can also be in JSONLines/MongoDb format with each JSON record on separate lines. You can also identify the array using Javascript notation.
🌐
DEV Community
dev.to › awaisalwaisy › 7-ways-to-convert-objects-into-array-in-javascript-35m4
7 ways to convert Objects into Array in JavaScript - DEV Community
February 12, 2023 - The for...in loop is a traditional looping method in JavaScript to iterate over the properties (keys) of an object. It can be used to convert an object into an array by extracting its values and forming a new array with them.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › entries
Object.entries() - JavaScript | MDN
const object = { a: "some string", b: 42, }; for (const [key, value] of Object.entries(object)) { console.log(`${key}: ${value}`); } // Expected output: // "a: some string" // "b: 42" ... An array of the given object's own enumerable string-keyed property key-value pairs.
🌐
GitHub
github.com › sudheerj › javascript-interview-questions
GitHub - sudheerj/javascript-interview-questions: List of 1000 JavaScript Interview Questions · GitHub
Practice 280+ JavaScript coding interview questions in-browser. Built by ex-FAANG interviewers. No AI-generated fluff. No fake reviews. Try GreatFrontEnd → 💡 ... The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces. ... Object literal property values can be of any data type, including array, function, and nested object. Note: This is one of the easiest ways to ...
Author   sudheerj
🌐
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(). Note that the Object.keys() method has been available since ECMAScript 2015 or ES6, and the Object.values() and Object.entries() ...
🌐
Medium
medium.com › dailyjs › rewriting-javascript-converting-an-array-of-objects-to-an-object-ec579cafbfc7
Rewriting JavaScript: Converting an Array of Objects to an Object. | by Chris Burgin | DailyJS | Medium
April 23, 2017 - What we do in the snippet above is use reduce, which returns accumulator (obj), to which we append each item in the array using that items id. This will convert our array of objects into an object of objects.
🌐
Reddit
reddit.com › r/learnjavascript › how to transform an array of numbers into objects?
r/learnjavascript on Reddit: How to transform an array of numbers into objects?
February 3, 2023 -

Solved: so the problem was I did not understand what everyone was saying by returning my array/result. I knew I was close, kind of, but was missing the final pieces of the puzzle until I saw the working code, then it made sense.

This is the solution I went with and it passed the check:

function transformToObjects(numberArray) {

return numberArray.map((num) => { let obj = { val: num }; console.log(obj); return obj; }); }

I'm still unsure why the console.log(obj) does not log this, but I presume it was used for testing and has something to do with the return keyword that makes it not display the obj variable.

____________________________________________________

Hi, I am stuck on an exercise from a course on Udemy and I'm not sure how to solve it.

I need to put through [1,2,3] in my argument and return [ Object({ val: 1 }), Object({ val: 2 }) ]

Below is my attempt at it:

function transformToObjects(numberArray) {
  // Todo: Add your logic
  // should return an array of objects

  //console.log(numberArray);
  numberArray.map((num) => {
    let numObj = { val: num };
    return numObj;
  });
}
transformToObjects([1, 2, 3]);

Note: I must use map() for this exercise. Any thoughts/help on this?

🌐
Codersvibe
codersvibe.com › convert-array-to-object
Convert Array to Object In JavaScript - Quick Method
We provide the best solutions in all languages like PHP, Laravel, Codeigniter, Nodejs, MySQL, AJAX, jQuery, JavaScript and Python with examples and demos.
🌐
CSVJSON
csvjson.com
CSVJSON - CSVJSON
Re-opened to community. ... Transpose: You can now transpose the csv data before conversion. Output object instead of array: By default an array of objects is output. You can now output an object or hash. The first column becomes the hash key. Any data pasted and converted on csvjson remains ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › values
Object.values() - JavaScript | MDN
Object.values() returns an array whose elements are values of enumerable string-keyed properties found directly upon object. This is the same as iterating with a for...in loop, except that a for...in loop enumerates properties in the prototype chain as well.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Convert array to object - JavaScript - The freeCodeCamp Forum
February 22, 2021 - Hello, Thanks in advance for the help, I’m currently a student developer and really having a hard time with my assignments. Here is the most recent and its simply converting an array into an object. I there is someone that wouldn’t mind be a mentor that would be extremely helpful. function main(objArr) { // console.log(objArr) let newObj = new Object(); console.log(newObj) for (let i = 0; i
🌐
Seanconnolly
seanconnolly.dev › javascript-object-to-array
JavaScript object to array · Sean Connolly
There are 3 JavaScript methods available to help us convert an object to an array.