How to Convert Object to an Array in JavaScript
Converting Object to an Array ES6 Way using object Keys(),Values() and entries() method:
const user = { fname: 'john', lname: 'doe', }; Object.keys(user); // ["fname", "lname"] Object.values(user); //["john", "doe"] Object.entries(user); //[["fname", "john"],["lname", "doe"]]
You can also Convert back to Array from Object using fromEntries() method:
const data = [ ["fname", "john"], ["lname", "doe"] ]; Object.fromEntries(data); //{fname: "john", lname: "doe"}