23-Aug-2022
.
Admin
Hi friends,
I am going to show you an example of how to convert the object to an array in node js. step by step explains convert object to array in nodejs . I want to show you convert object to an array in node.js. Here you will learn to convert object to array in node js example.
There are many ways to convert object to array node js. I will give you examples using Object.entries(). This function is used to convert object to array.
let's see below simple example with output:
Install Node JS
This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:
mkdir my-app
cd my-app
npm init
Example:
index.js
// create object
object = {
"first_name": "Piyush",
"last_name": "Kamani",
"job": "Developer"
}
// convert object to array
myArry = Object.entries(object);
console.log(myArry);
Output:
[
[ 'first_name', 'Piyush' ],
[ 'last_name', 'Kamani' ],
[ 'job', 'Developer' ]
]
I hope it can help you...
#Node JS