陳靖武
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 陣列與物件整合運用 ## 陣列與物件混合應用 * 在陣列與物件混和情境下,陣列裡面可以放多個物件,在物件中再寫詳細資料,如下範例: ```javascript= let market = [ { bossName: "Tom", bananaNum: 6, appleNum: 5, isClose: true }, { bossName: "John", bananaNum: 4, appleNum: 5, isClose: false } ] console.log(market); //讀取整個market陣列資料 ``` ![](https://i.imgur.com/T37Ij4Z.png) ## 陣列與物件混合讀取教學 * 接續上面程式讀取陣列位置0內的整個物件,用中括號尋找物件 ```javascript= console.log(market[0]); //讀取物件資料 ``` ![](https://i.imgur.com/i382FKE.png) * 讀取陣列[0]內的bannaNum屬性,用點號.尋找屬性 ```javascript= console.log(market[0].bossName); ``` 印出值為:![](https://i.imgur.com/AWuZjAD.png) ## JSON格式 [wiki百科介紹](https://zh.wikipedia.org/wiki/JSON) * 為何要有JSON格式:不同結構的資料庫之間需要有共通格式做傳遞 * 應用領域:JSON使用在JavaScript、Java、Node.js應用的情況比較多,PHP、C#等開發的WEB應用主要還是使用XML。 * 安裝JSON套件:[JSONVUE](https://chrome.google.com/webstore/detail/jsonvue/chklaanhfefbnpoihckbnefhakgolnmc?hl=zh-TW)。套件使用目的:可以將資料做友善的排版。 * 下載JSON資料範例: 1. :[電動車資訊.json](https://cdn.fs.teachablecdn.com/OPXa0mREqO3hpSLfVnQw),其為陣列格式(內包物件)。將陣列資料全部複製後,全部貼在all.js宣告變數的等號後面,在程式最後面加個分號。用console.log確認是否有儲存成功。 2. 前往網站JSON資料集,右鍵檢視原始碼,ctrl+a & ctrl+c貼到主控台的宣告變數等號後面,同樣最後面加上分號。 * JSON陣列格式中每一筆資料都是物件,讀取方式為陣列變數名稱[0]陣列第0筆資料,.後面為屬性格式。 ```javascript= console.log(data[0].kind); ``` ## 物件裡面包物件 * 當物件內的資料有更多詳細資訊時,可以使用物件包物件方式,注意裡面那層的物件需使用冒號而不是等號,且使用逗號隔開。 * 讀取資料使用點號法。 ```javascript= let home = { motherStatus: { age: 18, name: "Amy" }, fatherStatus: { age: 20, name: "Sam" }, dogs: 3 } console.log(home.motherStatus.age); console.log(home.fatherStatus.name); console.log(home.dogs); ``` ![](https://i.imgur.com/D0ikEAU.png) * 接續上程式篩選出自己想要的資料格式,並賦予到特定變數上 ```javascript== let arry=home.motherStus; console.log(arry); ``` ## 物件搭配if練習 * 範例一量測體溫: ![](https://i.imgur.com/SGRYPeO.png) * 先宣告湯姆狀態的物件,湯姆體溫可以直接在物件大括號內寫入也可以另外用點號法寫入資料。 * 開始寫判斷式,依據條件判斷可以或不可以進入且寫入屬性status的值。 * 最後再印出物件TomStatus。 ```javascript= let TomStatus = { name: "Tom", age: 30, status: "" } TomStatus.degree = 36.5; if (TomStatus.degree >= 37.5) { console.log("您不得進入"); TomStatus.status = "您不得進入"; } else { console.log("您可以進入"); TomStatus.status = "您可以進入"; } console.log(TomStatus); ``` * 假如客人的數量很多,可以改寫為宣告陣列,寫入第N筆資料,使用console.log確認資料是否寫入成功。開始寫判斷式if、else,代入您不得進入或您可以進入於status屬性和console.log。 * 最後確認陣列是否正確。可以修改變數degree的值或是陣列[N]來練習。 * 後續資料變多時,可以先處理第一筆資料,再用語法解決其他資料。 ```javascript= let peopleStatus = [ { name: "Tom", age: 30, status: "" }, { name: "Amy", age: 27, status: "" } ] peopleStatus[1].degree = 37.6; console.log(peopleStatus[1]); if (peopleStatus[1].degree >= 37.5) { peopleStatus[1].status = "您不得進入"; console.log("您不得進入") } else { peopleStatus[1].status = "您可以進入"; console.log("您可以進入") } console.log(peopleStatus[1]); ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully