Showing posts with label TypeScript. Show all posts
Showing posts with label TypeScript. Show all posts

TypeScript: Remove duplicate item in array

Posted by Unknown On Friday, July 21, 2017 10 comments

 this.carriers = this.carriers.filter((el, i, a) => i === a.indexOf(el))

TypeScript: Convert string to number

Posted by Unknown On Tuesday, July 11, 2017 0 comments

  this.customerid = Number(text);

JavaScript: Base64 encoding and decoding

Posted by Unknown On 0 comments
atob(): Decodes a string of data which has been encoded using base-64 encoding.
btoa(): Creates a base-64 encoded ASCII string from a "string" of binary data.

The "Unicode Problem": In most browsers, calling btoa() on a Unicode string will cause a Character Out Of Range exception. This paragraph shows some solutions.

Solution to unicode

TypeScript: Clone an object

Posted by Unknown On Monday, July 10, 2017 0 comments

let newObject = Object.assign({}, currentObject);

Angular 2: Format Date Time MM-dd-yyyy

Posted by Unknown On 0 comments




 Output: 07-09-2017 05:00 PM

TypeScript: Filter out array from another array (not in statement)

Posted by Unknown On Friday, July 7, 2017 0 comments

var arr1 = [1, 2, 3, 4, 5];
var arr2 = [2, 4];

var arr = arr1.filter(x => { return arr2.indexOf(x) === -1; });


TypeScript: Select fields from Array of Object

Posted by Unknown On Thursday, July 6, 2017 0 comments

var ids = this.products.map((p) => p.id);
var products= this.selectedProducts.map((p) => { p.id, p.name });

TypeScript: search item in array by field

Posted by Unknown On Thursday, June 29, 2017 0 comments
  
  public search(name: string): void {
    if (name.trim().length > 0) {
      this.employees = this.employeeSource.filter(x => x.name.toLowerCase().indexOf(name.trim().toLowerCase()) >= 0);
    }
  }  
  
  

TypeScript: ForEach Sum Field in Items of an Array

Posted by Unknown On 3 comments

  public getTotalWeight(): number {
    var total = 0;
    if (this.items != null && this.items.length > 0) {      
      this.items.forEach(x => total += x.weight);
    }
    return total;
  }