Jezyk Danzowki Jezyk Danzowki - 1 month ago 19
TypeScript Question

Angular2 Typescript Trim File Extensions from array

I was wondering if it is possible to trim file extensions from an array on Angular 2 TS.

I know it is easy to trim within JS, but wondered how easy it is to do within TS.

Lets same i have this data returned:

[ '1111111.pdf', '1111112.pdf' ]

How would I approach to trim the '.pdf' from the array?

I know in js you can use
but yano... any suggestions would be apprecaited


I'd use custom pipe.

Working Demo:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'extension' })

export class RemoveExtension implements PipeTransform {
  transform(item) {
    return item.substring(0, item.indexOf('.'))


import { Component } from '@angular/core';

  selector: 'my-app',
  template: `      
      <h1>Remove Extension:</h1>      
      <li *ngFor="let item of myData">{{item|extension}}</li>
export class AppComponent {
 myData=[ 'abc.pdf', 'xyz.pdf' ];