Object.keys

8 0 0
                                        

Object.keys(obj) - returns an arrays of keys.

syntax:

let array1 = Object.keys(object)

Note: The argument is an object. The Object.keys() method will return all the keys inside the object that you specify in an array form.

==================

let book1 = {

    title: "Reincarnated as a Slime",

    author: "Rimuru Senpai",

    published: 2021

};

function displayTheBook1(){

    let array1 = Object.keys(book1);

    document.writeln(array1);

}

==================

Result:

name,author,published


Note: In the tutorial, there are Object.values and Object.entries but when I tried to used it, it is not allowed. There is no such thing as those. Maybe because it was deprecated.


Javascript ProgrammingWhere stories live. Discover now