Q:

How to store CssValues in an Array in protractor automation with Typescript

I'm writing Protractor automation scripts in Typescript.
I have an array of webelements returned as ElementArrayFinder.
I need to store the 'font-weight' of each element in a separate array/ map and return it. 
My script shows the length of array is 0 even after Push statement. can someone please help to achieve this.
public getFontWeightOfElements () : promise.Promise<string>[]
{
    let array1 : promise.Promise<string>[] = [];
    //taskList is array of WebElements
    this.taskList.each((element) =>
    {
        element.getCssValue('font-weight')
          .then((value) =>
          {
            array1.push(value);
          })
    })
    console.log(array1.length); // getting 0 each time
    return array1;

A:

The problem is that you are returning the array before the asynchronous operations, the Promises, have been resolved. Here is a solution
getFontWeightOfElements(): Promise<string[]> {
  return this.taskList.map(element => element.getCssValue('font-weight'));
}

Note the return type is no longer an array of Promises but rather a Promise for an array.
Consume like this
getFontWeightOfElements().then(fontWieghts => {
  fontWieghts.forEach(fontWieght => {
    console.log(fontWeight);
  });
});

