Closed Bug 1258260 Opened 10 years ago Closed 10 years ago

slice, splice is not a function (Array()) doubting any work

Categories

(Core :: JavaScript Engine, defect)

45 Branch
x86
Windows Vista
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: jmichae3, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.0; rv:45.0) Gecko/20100101 Firefox/45.0 Build ID: 20160315153207 Steps to reproduce: function deleteBlankRows(tableid) { var i,j,s,rows=document.getElementById(tableid).rows,count=0; console.log(rows.prototype); for (i=0; i < rows.length; i++) { count=0; for (j=0; j < rows[i].cells.length && i < rows.length && i>=0; j++) { s=rows[i].cells[j].innerHTML.replace(/\s*&nbsp;\s*|\s*/g,''); rows[i].cells[j].innerHTML=s; if (""==s) { count++; } } if (rows[i].cells.length==count) { rows=rows.splice(i,1); i--; } } } Actual results: undefined pwd.html:2893:2 TypeError: rows.splice is not a function d.html:2904:9 The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. pwd.html Expected results: should have worked. followed MDN example for splice.
OS: Unspecified → Windows Vista
Hardware: Unspecified → x86
The type of HTMLTableElement.rows is HTMLCollection, not Array. https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/rows https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection So you need to convert it into an Array before calling any of Array methods, or, just call HTMLTableElement.deleteRow if you want to remove the row. https://developer.mozilla.org/ja/docs/Web/API/HTMLTableElement/deleteRow Then, could you tell me which MDN example you followed? If the example calls splice on HTMLCollection, I'd like to fix the example.
Flags: needinfo?(jmichae3)
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice using spec for arguments.(In reply to Tooru Fujisawa [:arai] from comment #1) > The type of HTMLTableElement.rows is HTMLCollection, not Array. > > https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/rows > https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection > > So you need to convert it into an Array before calling any of Array methods, > or, just call HTMLTableElement.deleteRow if you want to remove the row. > > https://developer.mozilla.org/ja/docs/Web/API/HTMLTableElement/deleteRow > > > Then, could you tell me which MDN example you followed? If the example > calls splice on HTMLCollection, I'd like to fix the example. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice using spec for arguments. //attempt to delete 2 [1,2,3,4,5].deleterow(1).join(","); TypeError: [1, 2, 3, 4, 5].deleterow is not a function [1,2,3,4,5].deleteRow(1).join(","); TypeError: [1, 2, 3, 4, 5].deleteRow is not a function [1,2,3,4,5].deleterow(1,1).join(","); TypeError: [1, 2, 3, 4, 5].deleterow is not a function https://developer.mozilla.org/en-US/search?q=table https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ note that deleteRow is not listed under table or Array().
Flags: needinfo?(jmichae3)
deleteRow is a methods on HTMLTableElement, not Array. https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteRow https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement HTMLTableElement is an interface that is implemented by table element. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table so, if you get table element by document.getElementById or something, in `table` variable, you can call deleteRow like `table.deleteRow(1)`. Those are totally different things than Array.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.