Koj ua li cas los ntawm ib qho khoom hauv JavaScript?
Koj ua li cas los ntawm ib qho khoom hauv JavaScript?

Video: Koj ua li cas los ntawm ib qho khoom hauv JavaScript?

Video: Koj ua li cas los ntawm ib qho khoom hauv JavaScript?
Video: txhob hnov qab kuv lub npe - Bee lee [Official MV] 2022-23 2024, Kaum ib hlis
Anonim

Thaum koj voj ntawm ib yam khoom nrog forin lub voj , koj yuav tsum tau xyuas seb cov cuab yeej belongs rau lub khoom . Koj tuaj yeem ua qhov no nrog hasOwnProperty.

Txoj hauv kev zoo dua los voj los ntawm cov khoom yog thawj zaug hloov cov khoom rau hauv ib qho array. Tom qab ntawd, koj hla lub array.

  1. yuam sij.
  2. tus nqi.
  3. nkag.

Hais txog qhov no, ua li cas koj hla ib qho khoom hauv JavaScript?

Ib txoj hauv kev zoo dua thiab ua tau zoo dua los ntawm kev sib tw khoom hauv ES6 yog thawj zaug hloov cov khoom nyob rau hauv ib tug array siv Yam khoom . key(), Yam khoom . tus nqi (), Yam khoom.

Yeej, yog tias koj tsim ib yam khoom ntawm obj = {foo: 'bar'} los yog ib yam dab tsi thereabouts, tag nrho cov khoom muaj enumerable.

  1. rau… nyob rau hauv lub voj.
  2. Yam khoom.
  3. Yam khoom.
  4. Yam khoom.
  5. Yam khoom.

Tsis tas li ntawd, koj yuav ua li cas tawm tsam kev nkag? Yam khoom . nkag () txoj kev siv los xa rov qab ib qho array uas muaj cov cuab yeej suav nrog [qhov tseem ceeb, tus nqi] khub ntawm khoom uas tau dhau los ua qhov parameter. Qhov kev txiav txim ntawm cov khoom yog tib yam li uas tau muab los ntawm looping tshaj cov khoom muaj nqis ntawm cov khoom manually. Yam khoom.

Ib yam li ntawd, koj tuaj yeem nug, Kuv yuav ua li cas los ntawm cov yuam sij khoom?

Yam khoom . yuam sij () yuav nyob rau hauv khoom uas koj xav tau voj dhau raws li nws qhov kev sib cav. Nws yuav rov qab ib qho array uas muaj cov npe khoom xws li. yuam sij . Tom qab ntawd peb tuaj yeem siv array txoj hlua txoj kev xws li rau Txhua, daim ntawv qhia thiab txo kom retrieve qhov tseem ceeb ntawm txhua tus tus yuam sij.

Kuv puas tuaj yeem siv forEach ntawm ib qho khoom?

Ib qho yooj yim rauTxhua () Kev siv rau Arrays, Yam khoom thiab NodeLists uas tshem tawm rov ua dua khoom nrhiav thiab array notations. Hla hauv txhua hom thiab nws yuav rov hais dua thiab xa rov qab tag nrho cov khoom tsim nyog xws li index, khoom, khoom, nqi thiab khoom . Lub syntax yog ib txoj haujlwm yooj yim wrapper.

Pom zoo: