Hey stackoverflow, I was working on a project that was meant to take the methods and properties of different API's and then making a system that would allow these to be chained together and used with less technical knowledge.
One of the basic requirements of this project is being able to parse out an object into its properties and its functions. Having tried a couple of different approaches with no luck, I noticed (see picture) that vscode could tell what parts of an object are methods and which are properties, which left me wondering how i could actually utilize this functionality, as in is there a function that would return all the properties of an object?
I know Object.keys() returns the string value of all the keys of an object, which is a good start, but i also need the actual objects held by these keys.
I've also stumbled onto Object.getPrototypeOf(obj), which returns the prototype of a function, and at least as far as i understand the prototype holds all the methods, and as such we should be able to go through all the prototypes nested inside the first prototype to find all the methods we can use. (atleast this is what im attempting next) One of the concerns I'm imagining is that some methods are also held in keys, and these wouldn't be caught in this way, I'm imagining.
So my overarching question is if there's a smart way to access these properties and methods or to simply sort it outright
You can use Object.entries() and get both, key and value // -> [[key, value], [key, value]]
Try:
let list = Object.entries(window).map(([key, value]) => ({[key]: typeof value}))
console.log(list)