Este artículo describe el método de simulación de la tabla JS. Compártelo para su referencia. Los métodos específicos son los siguientes:
<! DocType html> <html> <head> <meta charset = "utf-8"> <title> list </title> <script> function list () {this.listsize = 0; this.pos = 0; this.datastore = []; // Inicializar una matriz vacía para guardar el elemento de lista this.clear = clare; this.find = find; this.ToString = toString; this.insert = insert; this.append = append; this.remove = eliminar; this.front = front; this.end = end; this.prev = prev; this.next = siguiente; this.length = longitud; this.currpos = Currpos; this.moveto = Moveto; this.getElement = getElement; this.length = longitud; this.contains = contiene; function append (element) {this.datastore [this.Listize ++] = element; }; function find (element) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === element) {return i; }} return -1; } function eliminar (elemento) {var foundat = this.find (elemento); if (Foundat! =-1) {this.datastore.splice (Foundat, 1); esto. Listicizar--; elemento de retorno; // return True igualmente fue así, lo cambié a elemento} else {return false; }} longitud de función () {return this.ListSize; } function toString () {return this.datastore; } function insert (elemento, después) {var insertpos = this.find (después); if (insertpos! =-1) {this.datastore.splice (insertPos+1,0, elemento); this.listSize ++; devolver verdadero; } else {return false; }} function clear () {eliminar this.datastore; this.listSize = 0; this.pos = 0; this.datastore = []; } función contiene (elemento) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === element) {return true; }} return false; } function front () {this.pos = 0; } function end () {this.pos = this.ListSize-1; } function prev () {// if (this.pos> 0) {--this.pos; //}} function next () {// if (this.pos <this.ListSize-1) {++ this.pos; //}} function Currpos () {return this.pos; } función moveto (pos) {this.pos = pos; } function getElement () {return this.datastore [this.pos]; }} var list = new List (); list.append ({nombre: 'Xia Guangcheng', sexo: 'masculino'}); list.append ({nombre: 'Jiang rongsheng', sexo: 'masculino'}); list.append ({nombre: 'du qiang', sexo: 'masculino'}); list.append ({nombre: 'qiaohua', sexo: 'femenino'}); list.append ({nombre: 'Fang yang', sexo: 'masculino'}); list.append ({nombre: 'Fang yang', sexo: 'masculino'}); for (list.front (); list.currpos () <list.length (); list.next ()) {var item = list.getElement (); if (item.sex == 'femenino') {list.remove (item); }} for (list.front (); list.currpos () <list.length (); list.next ()) {var item = list.getElement (); console.log (item.name); } </script> </head> <body> </body> </html>Espero que este artículo sea útil para la programación de JavaScript de todos.