Tim Liberty
Tim Liberty

Reputation: 2149

Typescript select property

I am new to Typescript. I want to select property

This is my observable

 entries:Observable<Log[]>;

Log class contains many properties like _id, name, etc. Now I want to get an array of string[] by extracting name out of the observable. How would I do that?

Is there any documentation available for this? I am finding this Typescript thing too tough IMHO

Upvotes: 0

Views: 1520

Answers (2)

user7122183
user7122183

Reputation:

var source = entries.pluck('name').toArray();

var subscription = source.subscribe(names => {
  console.log(names);
});

Upvotes: 0

Miroslav Jonas
Miroslav Jonas

Reputation: 6637

Not sure if I understood correctly what you mean by extracting name out of the observable. If you want to extract all the property names into array of strings you can do it like this:

entries.subscribe((logs: Log[]) => {
   if (logs.length) {
      // extract all defined property names from first log
      let props = Object.keys(logs[0]);
      // do something with properties
   }
});

Upvotes: 2

Related Questions