- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert an object into an array in JavaScript?
To convert an object into an array, use push() in JavaScript. Following is the code −
Example
studentDetails= [ { studentName:"Chris",studentMarks:34}, { studentName:"David",studentMarks:89} ] var convertIntoArray = []; for (var i = 0; i < studentDetails.length; i++) { convertIntoArray.push(studentDetails[i].studentName); } console.log(convertIntoArray);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo35.js.
Output
This will produce the following output.
PS C:\Users\Amit\JavaScript-code> node demo35.js [ 'Chris', 'David' ]
Advertisements