# Returning an array from backend

**URL:** <https://forum.wixstudio.com/t/returning-an-array-from-backend/3836>\
**Category:** Ask the community\
**Tags:** code, wix-stores, question\
**Created:** [November 18, 2021, 5:03am UTC](https://forum.wixstudio.com/t/returning-an-array-from-backend/3836 "2021-11-18T05:03:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![widstje](https://avatars.discourse-cdn.com/v4/letter/w/cdc98d/32.png) [@widstje](https://forum.wixstudio.com/u/widstje)\
**Post date:** [November 18, 2021, 5:03am UTC](https://forum.wixstudio.com/t/returning-an-array-from-backend/3836/1 "2021-11-18T05:03:47Z")

</div>

I have been struggling for an hour to get this working. I don’t know what I am doing wrong and need a second set of eyes.

The goal is to read a table with WixDataQuery while in the backend, and then call this function on the frontend. Once there I will load the results into a table. I put in the console check in to make sure rowsToLoad was holding data correctly (it is). The error I get is when calling the function. I’m getting “Promise\<\>” in the console.

The code is for a leaderboard so it organizes, limits to top 100 players, assigns a rank to each row of data and pushes out to table.

**export async function** get\_top\_players () {  
**let** results = **await** wixData . query ( “GameData” )  
. descending ( “pEarnings” )  
. limit ( 100 )  
. find ()  
. then (( results ) =\> {  
**for** ( **var** i = 0 ; i \< results . length ; i ++) {  
**const** rowsToLoad = results . items . map (( r , i ) =\> {  
**return** { “pName” : r . pName , “table\_index” : i + 1 , “pExp” : r . pExp , “title” : r . title , “pEarnings” : r . pEarnings }  
})  
console . log ( rowsToLoad ); //Data stored correct here  
**return** rowsToLoad ;  
}  
});  
}

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [November 18, 2021, 5:47am UTC](https://forum.wixstudio.com/t/returning-an-array-from-backend/3836/2 "2021-11-18T05:47:54Z")

</div>

Frontend:

```javascript
import { get_top_players } from 'backend/xxxxxxxx.jsw' //how is called JSW-FILE?

```

```javascript
$w.onReady(async()=>{
   let myRecievedDataFromBackend = await get_top_players();
});

```

Backend:

```javascript
exportasyncfunction get_top_players(){
   return wixData.query("GameData")
   .descending("pEarnings")
   .limit(100)
   .find()
   .then((results)=>{console.log(results);
      for(vari=0;i<results.length;i++){
         const rowsToLoad = results.items.map((r,i)=>{
            return{
               "pName":r.pName, 
		"table_index":i+1, 
		"pExp":r.pExp, 
		"title":r.title, 
		"pEarnings":r.pEarnings
	     }
	 });
	console.log(rowsToLoad); return rowsToLoad;
	}
   });
}

```
