undefined type #95
-
After receiving [Promise object] i extract the obj[0]. How do I access the value? |
Beta Was this translation helpful? Give feedback.
Answered by
MrRefactoring
Jan 6, 2021
Replies: 1 comment 1 reply
-
You are trying to take an index value from Promise. You can't do that in JavaScript, you have to wait for Promise to execute first, and then work with the data. This library supports 3 variants of data retrieval: Callbackimport { Client } from 'jira.js';
const client = new Client({ host: '...' });
client.projects.getAllProjects({}, (error, data) => {
console.log('error', error);
console.log('data', data);
}); Promiseimport { Client } from 'jira.js';
const client = new Client({ host: '...' });
client.projects.getAllProjects()
.then((data) => console.log('data', data))
.catch((error) => console.log('error', error)); Async/Awaitimport { Client } from 'jira.js';
const client = new Client({ host: '...' });
async function showAllProjects() {
try {
const data = await client.projects.getAllProjects();
console.log('data', data);
} catch (error) {
console.log('error', error);
}
}
showAllProjects(); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MrRefactoring
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are trying to take an index value from Promise. You can't do that in JavaScript, you have to wait for Promise to execute first, and then work with the data. This library supports 3 variants of data retrieval:
Callback
Promise
Async/Await