Este artigo descreve o método de simulação da tabela JS. Compartilhe para sua referência. Os métodos específicos são os seguintes:
<! doctype html> <html> <head> <meta charset = "utf-8"> <title> list </title> <cript> list () {this.listsize = 0; this.pos = 0; this.datastore = []; // inicialize uma matriz vazia para salvar o elemento da lista this.clear = clear; this.find = find; this.toString = ToString; this.insert = insert; this.append = Anexe; this.Remove = remover; this.front = front; this.end = end; this.prev = prev; this.Next = Next; this.length = comprimento; this.currpos = currpos; this.moveto = moveto; this.getElement = getElement; this.length = comprimento; this.contains = contém; função append (element) {this.datastore [this.listsize ++] = element; }; function find (element) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === element) {return i; }} retornar -1; } função remover (elemento) {var foundat = this.find (elemento); if (foundat! =-1) {this.datastore.splice (foundat, 1); this.Listsize--; elemento de retorno; // Return True True Era originalmente assim, eu o alterei para elemento} else {return false; }} função comprimento () {return this.listsize; } função tostring () {return this.datastore; } função insert (elemento, depois) {var insertPos = this.find (depois); if (insertpos! =-1) {this.datastore.splice (insertpos+1,0, elemento); this.Listsize ++; retornar true; } else {return false; }} function clear () {exclate this.datastore; this.Listsize = 0; this.pos = 0; this.datastore = []; } função }} retornar false; } função front () {this.pos = 0; } function end () {this.pos = this.listsize-1; } função prev () {// if (this.pos> 0) {--this.pos; //}} função a seguir () {// if (this.pos <this.listsize-1) {++ this.pos; //}} função currpos () {return this.pos; } função moveto (pos) {this.pos = pos; } function getElement () {return this.datastore [this.pos]; }} var lista = new List (); list.append ({name: 'xia guangcheng', sexo: 'masculino'}); list.append ({name: 'Jiang Rongsheng', sexo: 'masculino'}); list.append ({name: 'du qiang', sexo: 'masculino'}); list.append ({name: 'qiaohua', sexo: 'feminino'}); list.append ({name: 'Fang yang', sexo: 'masculino'}); list.append ({name: 'Fang yang', sexo: 'masculino'}); for (list.front (); list.CurrPos () <list.Length (); list.Next ()) {var item = list.getElement (); if (item.sex == 'feminino') {list.remove (item); }} para (list.front (); list.currpos () <list.length (); list.Next ()) {var item = list.getElement (); console.log (item.name); } </sCript> </head> <body> </body> </html>Espero que este artigo seja útil para a programação JavaScript de todos.