how can i convert object to an array javascript code example
Example 1: convert object to array javascript
var object = {'Apple':1,'Banana':8,'Pineapple':null};
var k = Object.keys(object);
var v = Object.values(object);
Example 2: javascript convert array to object
function arrayToObject(arr) {
var obj = {};
for (var i = 0; i < arr.length; ++i){
obj[i] = arr[i];
}
return obj;
}
var colors=["red","blue","green"];
var colorsObj=arrayToObject(colors);
Example 3: how can i convert object to an array javascript
const entries = Object.entries(person);
console.log(entries);
Code language: JavaScript (javascript)