Convert an object into an array or a string

1005 0 0 0

Last Updated : 2024-04-28 13:37:55

In order to convert an object into an array, this is easy using the Object.values() method. On the other hand if you want to convert an object into a string, any Object can be converted to a string using the JSON.stringify() method.


  1. Convert an object into an array using Object.values()
    const PHP = new Object();
    PHP.name = 'Advanced PHP Techniques';
    PHP.length = 40 ;
    PHP.price = 3000 ;
    PHP.discount = function() {
    console.log(this, this.price);
    }

    const ObjectArray = Object.values(PHP);
    console.log(ObjectArray); // This is now an Array?

    Mohammed Anwar

    Mohammed Anwar

    Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .