This is my function code here I want to return a 2d array in "a" variable;
var a = [[]];
var b = [[]];
var j = 0;
var i = 0;
let is = 2;
let desiredFields = ['display_name', 'phone'];
function myFunction() {
console.log('Loading contacts...');
let timer = new Date().getTime();
Contacts.getContactsWorker(desiredFields).then((result) => {
console.log(`Loading contacts completed in ${(new Date().getTime() - timer)} ms.`);
console.log(`Found ${result.length} contacts.`);
deger = result.length;
a = new Array(result.length);
for (i = 0; i < result.length; i++) {
for (j = 0; j < 2; j++) {
if (j == 0) a[i][j] = result[i].display_name;
if (j == 1) a[i][j] = result[i].phone[0].number;
}
}
});
return a;
}
This is the code to call the function;
getItems(): Array <IDataItem> {
b = myFunction();
while (is <= 5) {
this.items.push({
id: is,
name: b[0][0],
description: b[0][1]
});
is = is + 1;
}
return this.items;
}
if my code is not correct ? how do I send a 2d array to a function ?