Not able to return an array containing column values from an ag-grid table back to the function



I have written a function which reads a given column in ag-grid and storing it in an array.

getSortedText(columnName: string){
var testArrayAsc = [];
element.all(by.css(' > [role="row"]')).then(function(count) {
  console.log("Row Count= ", Object.keys(count).length);
  for (let rowNo = 0; rowNo < Object.keys(count).length; rowNo++) {
    element.all(by.css(String.Format(" div[ row-index='{0}'] > [col-id='{1}']", rowNo, columnName))).map(function (Element) {
     Element.getText().then(function (result) {
       console.log("Result Asc :: " + result);
}).then(function () {
    return testArrayAsc;

I am calling this function from my test by:

console.log('Array::', homepage.getSortedText('Betreff'));

But I am getting "Array:: undefined" as output.
And If i modify my code like this:

homepage.getSortedText('Betreff').then(function (a) {

Then I am getting this error message in IDE: "Property 'then' doesnot exist on type 'void'".
Please help. Thanks in advance.

1 Answer: 

getSortedText doesn't return anything, hence it being void type and not having a then method.

There's a lot of missing information but a starting point is to return the Promise you're creating.

return element.all(