Yuav Ua Li Cas Thiaj Teeb Tau Qhov Array

Cov txheej txheem:

Yuav Ua Li Cas Thiaj Teeb Tau Qhov Array
Yuav Ua Li Cas Thiaj Teeb Tau Qhov Array

Video: Yuav Ua Li Cas Thiaj Teeb Tau Qhov Array

Video: Yuav Ua Li Cas Thiaj Teeb Tau Qhov Array
Video: 💞🎯🌐#Hais txog yuav ua li cas yus thiaj nrhiav tau yus tus kheej 🌐🎯9/30/2021 2024, Kaum ib hlis
Anonim

Tus kwv cov ntsiab lus sau ua lus JavaScript yog tam sim no qhov siv cov lus sau tshaj plaws los ua cov nplooj ntawv sib tham. Yuav luag txhua zaus, txhawm rau daws cov teeb meem nyuaj uas siv hom lus no, koj yuav tsum tau siv cov qauv duab. Cov ntawv sau pib siv cov kab los ntawm kev tshaj tawm nws. Cia peb pom tseeb li cas thiaj ua tiav qhov no.

Arrays hauv JavaScript
Arrays hauv JavaScript

Tsim nyog

Yooj yim kev paub ntawm JavaScript

Cov Lus Qhia

Kauj ruam 1

Muaj ob peb txoj hauv kev los tsim cov JavaScript array. Piv txwv, zoo li qhov no: var sampleArray = [element_0, element_1, element_2, element_2]; Cov kab no tsim ib qho kev ntsuas plaub ntu ntev. Yog tias koj tsis qhia lub ntsiab ntsiab lus, tom qab ntawd ib qho khoob khoob yuav raug tsim: var emptyArray =;

Kauj ruam 2

Lwm txoj hauv kev los txhais qhov array: var sampleArray = Array tshiab (element_0, element_1, element_2, element_2); Thiab cov kev xaiv no yuav tsim ib qho plaub ntu ntev. Thiab ntawm no, yog tias koj tsis sau cov khoom array, tom qab ntawd cov array yuav raug tsim khoob: var emptyArray = tshiab Array (); Nyob rau hauv xws li npliag, tom qab tshaj tawm, koj tuaj yeem tsim ob peb lub ntsiab nrog cov ntsuas tsis ua raws txhua lwm yam. Piv txwv li: var emptyArray = tshiab Array ();

emptyArray [4] = 47;

emptyArray [792] = 1; Tsis zoo li, piv txwv li arrays hauv C hom lus, cov kab ntawv no yuav nyob hauv lub cim xeeb xav tau tsuas yog khaws ob qho kev tawm, tsis yog 793. Koj tuaj yeem tsim ib qho khoob ntawm qhov ntev, tag nrho cov ntsiab lus ntawm cov uas yuav muaj tus nqi "undefined": var emptyArray = Array tshiab (8); Lub khoob khoob no yuav muaj 8 yam, uas nws qhov nqi tsis muaj kev txwv.

Kauj ruam 3

Rau ib qho ntawm cov qauv txheej txheem saum toj no ntawm kev tsim, array ntsiab tuaj yeem yog tus lej sib txuas lossis cov zauv seem, cov hlua thiab cov nqi tsim nyog. Arrays tseem tuaj yeem yog cov keeb kwm ntawm lwm yam arrays. Ib qho piv txwv ntawm kev tsim cov kab uas muaj ib qho kev ua ntawm txhua yam ntawm cov ntawv teev: var mixedArray = [4, 3.14, "ntawv nyeem", muaj tseeb, [47, 8.1] Vim tias ib qho array tuaj yeem yog ib qho khoom siv ntawm lwm yam, nws yog yooj yim to taub yuav ua li cas los tsim cov duab ntawm qhov ntau. Ib qho piv txwv ntawm kev tsim cov duab peb seem: var multiDimArray = [1, tseeb], [8, tseeb], 3.14], "ntawv nyeem", 42];) Cov no yog tag nrho cov lej muaj npe. Cov khoom yuav tsum raug siv los tsim kev sib txuam (npe) cov qauv hauv JavaScript.

Pom zoo: