Movatterモバイル変換


[0]ホーム

URL:


LoginSignup
2

Go to list of users who liked

5

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

async/awaitで非同期処理の完了を待つ

Posted at

①非同期処理をおこなう関数を宣言

const関数名=async()=>{constmessage='GitのユーザーIDは';consturl='https://api.github.com/users/taizo-pro'

②awaitをつけ、fetchが実行完了するまで次に進まなくさせる

// jsonにreturnされた値が入るconstjson=awaitfetch(url).then(res=>{console.log('非同期処理成功時のメッセージです')returnres.json()}).catch(error=>{console.error('非同期処理失敗時のメッセージです。',error)returnnull});constusername=json.login;console.log(message+username)}関数名()
2

Go to list of users who liked

5
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2

Go to list of users who liked

5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?


[8]ページ先頭

©2009-2025 Movatter.jp