Get a user object by username or id javascript

It is difficult to answer without some more context. You can always do this: (try it in the dev tools for Meta)

Discourse.User.findByUsername("David_Taylor").then(function(user){
   console.log("User Found", user);
});

But that will result in an additional request to the server, which may not be necessary.

What are you trying to achieve?