スキップしてメイン コンテンツに移動

javascriptでオブジェクトが空かどうかをどう調べばいい?

javascriptでは、配列が空かどうかを調べるには、
array.length === 0で判断すればいいですが、

objectは、どうすればいい?

例)

var hoge = {
    fuga: 1,
    moga: 2,
};

console.log(Object.keys(hoge).length === 0);

結果が、trueなら、空と判断できるわけ。

以上。

コメント

このブログの人気の投稿

gitよく使うコマンド集

よく使うgitのコマンド集をまとめてみた。 1.ローカルリポジトリの登録  #git init 2.gitの状態を確認  #git status 3.gitのファイルを追加  #git add . 4.ローカルのマスタにコミットする  #git commit -m "体温管理アプリの初期化" 5.リモートリポジトリを登録する  #git remote add origin https://github.com/ユーザーID/リポジトリ名  例)git remote add origin https://github.com/githubkyo/taionkanri 6. リモートリポジトリの変更履歴の取得 git fetch origin master 7.差分のあるファイル名を表示 > git diff --name-status ローカルブランチ名 origin/リモートブランチ名 【例】 > git diff --name-status master origin/master 8.リモートのファイルのみをローカルに反映する。 git checkout origin/master --src/Eccube/Resource/template/default/default_frame.twig 9.別ブランチをマスタへマージする git checkout master git merge other_branch 以上で、随時更新していく予定。

sendmailをgmail経由で送信する設定

 1.sendmail.iniで下記の設定を行う。 ------------------------------- smtp_server=smtp.gmail.com smtp_port=465 auth_username=youraccount@gmail.com auth_password=youraccountpassword force_sender=youraccount@gmail.com ------------------------------- 2.gmailでの設定 https://myaccount.google.com/securityへアクセスし、 安全性の低いアプリのアクセス 「オフ―」から「オン」に変える。 3.php.iniでsendmail_pathを設定する。 [mail function] ; For Win32 only. ; http://php.net/smtp ;SMTP = localhost ; http://php.net/smtp-port smtp_port = 465 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from ="admin@wampserver.invalid" ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = "sendmailフォルダーのパス\sendmail.exe -t" 4.Apacheを再起動すれば、sendmailが使えるようになる。 以上です。