Cov txheej txheem:

Yuav ua li cas koj khoob ib qho array hauv JavaScript?
Yuav ua li cas koj khoob ib qho array hauv JavaScript?

Video: Yuav ua li cas koj khoob ib qho array hauv JavaScript?

Video: Yuav ua li cas koj khoob ib qho array hauv JavaScript?
Video: Thaj Chaw Qub Instrumental + Lyrics - Kawm Muas & Maiv Huas Hawj 2024, Hlis ntuj nqeg
Anonim

Hauv Javascript yuav ua li cas rau khoob ib qho array

  1. Hloov nrog qhov tshiab array -arr =; Qhov no yog txoj kev ceev tshaj plaws.
  2. Teem qhov ntev prop rau 0 − arr.length = 0. Qhov no yuav tshem tawm qhov uas twb muaj lawm array los ntawm kev teeb tsa nws qhov ntev mus rau 0.
  3. Splice tag nrho array . arr.splice(0, arr.length) Qhov no yuav tshem tawm tag nrho cov ntsiab lus ntawm lub array thiab yuav ua tau huv si tus thawj array .

Hais txog qhov no, kuv yuav ua li cas thiaj kuaj tau yog tias ib qho array khoob hauv JavaScript?

Cov array tuaj yeem kuaj xyuas yog tias nws yog khoob los ntawm kev siv lub array . ntev khoom. Cov cuab yeej no rov qab cov naj npawb ntawm cov ntsiab lus hauv array . Yog tias tus lej ntau dua 0, nws ntsuas qhov tseeb.

Qhov thib ob, ua li cas koj khoob qhov khoom hauv JavaScript? tsis txaus ntseeg

  1. function isEmpty(obj) { for(var key in obj) { if(obj. hasOwnProperty(key)) return false; } rov muaj tseeb; }
  2. var myObj = {}; // Empty Object if(isEmpty(myObj)) { // Object is empty (Would return true in this example) } else { // Object is NOT empty }
  3. Yam khoom. tsab ntawv.
  4. var myObj = { myKey: "Qee tus nqi" } if(myObj.

Ib yam li ntawd, nws tau nug, ua li cas koj pop ib qho array hauv JavaScript?

JavaScript muab plaub txoj hauv kev ntxiv lossis tshem tawm cov khoom los ntawm qhov pib lossis xaus ntawm arrays:

  1. pop(): Tshem tawm ib yam khoom los ntawm qhov kawg ntawm ib qho array.
  2. push(): Ntxiv cov khoom mus rau qhov kawg ntawm ib qho array.
  3. shift(): Tshem ib yam khoom los ntawm qhov pib ntawm ib qho array.
  4. unshift(): Ntxiv cov khoom rau qhov pib ntawm ib qho array.

Yuav ua li cas koj append rau ib array?

Muaj ob peb txoj hauv kev los ntxiv ib qho array hauv JavaScript:

  1. 1) Txoj kev thawb () ntxiv ib lossis ntau lub ntsiab lus mus rau qhov kawg ntawm ib qho array thiab xa rov qab qhov ntev ntawm cov array.
  2. 2) Txoj kev unshift() ntxiv ib lossis ntau lub ntsiab lus rau qhov pib ntawm ib qho array thiab rov qab qhov ntev ntawm cov array: var a = [1, 2, 3]; a.

Pom zoo: