How to return value from a promise

const getVideoCount = () => {
      const instance = VideoStore.deployed().then(instanceRes => {
        const accounts = web3.eth.getAccounts().then(instanceAcc => {
          const count = instanceRes.getVideoListCount
              from: instanceAcc[0]
            .then(res => {

I want the value of console.log(res["words"][0]);
How do I do that?

Edit: Code formatting

console.log doesn’t return a value at all. If you’re referring to getting the value that you’re logging, you have to use it in the .then callback, e.g.

            .then(res => {

There’s no way to otherwise make a Promise “return” something back to synchronous code – once you start using them, you’re stuck with them.

That’s true, but you can keep chaining as many promises as you like using then.

new Promise(resolve => setTimeout(() => resolve(6), 1000))
  .then(res => res * 7)
  .then(newRes => console.log(newRes)) // logs 42 after 1 second
1 Like

@lionel-rowe @chuckadams I solved it by passing the res["words"][0] value to a function and returning that value. It is sort of a hack/workaround, and thought you guys should know I figured it out.