Philippe Corrèges
Philippe Corrèges

Reputation: 689

How to get the correct type shown with TypeOf()?

When using

const source = Observable.from([{name: 'Joe', age: 30}, {name: 'Frank', age: 20},{name: 'Ryan', age: 50}]);
console.log(typeof (source));

The Type is written as Object().

Is there a way to have more precise information? I would like to know if it is an Observable().

Thanks and Regards

Upvotes: 0

Views: 65

Answers (2)

Kousher Alam
Kousher Alam

Reputation: 1055

you can use :-

source.constructor

source.constructor.prototype

source.constructor.toString().indexOf // for logical check 

instanceof //operator.

It's depend on what's your need.

Upvotes: 2

Nitzan Tomer
Nitzan Tomer

Reputation: 164217

All class instances will have typeof of "object", that's just how javascript works.

If you want to know whether or not source is an instance of Observable then use instanceof:

console.log(source instanceof Observable);

Upvotes: 4

Related Questions