I want to get the names of all the clients which are stored in a constructor function.
let Client = function(name, feedback){
this.clientName = name;
this.clientFeedback=feedback;
}
let client1 = new Client('Jo', 'Hello')
let client2 = new Client('Mark', 'Bye')
let clientKeys = Object.keys(Client);
For (let i=0; i<clientKeys.length; i++){
Console.log(Client.clientName)}
But this code doesnt work.
Can I use object.keys here?
I'm absolutely beginner, so I hope I'm asking well.
Forloop andConsolearen't going to work. Generally speaking, instantiatable functions (i.e.client) should be uppercase.Object.keys(client);will return an empty array asclient, since it is a constructor function, it doesn't have keys of its own, only instances likeclient1andclient2doconst clients = [client1, client2];andfor (const client of clients) { console.log(client.clientName); }Object.keysnor aforloop, just doconsole.log(client1.clientName);