javascript - slice not working as expected on my array -
i have array scraped webpage:
myvar = document.queryselectorall('#tblitinerarymodulestaydetail > tbody > tr')
which in console returns array:
what need subset array:
- start 3rd item
- then keep every odd number of items
so need subset of var items 3 , 5 in it.
i tried: myvar.slice(3,5)
. returned error "undefined not function"
had been successful have array 3 items. i'd need subset on keeping odd items in array.
how subset myvar have variable items 3 , 5 left in it? if myvar length 10. how subset include items 3, 5, 7, 9?
myvar = document.queryselectorall('#tblitinerarymodulestaydetail > tbody > tr')
myvar nodelist , it's not array. can't use array functions in there.
but can use apply
or call
array functionality on nodelist.
how functionality?
array.prototype.slice.call(myvar, 3,5);
now can use slice
in nodelist.
but actual question, subset matching particular criteria not possible via slice well.
you must iterate through elements , manually.
Comments
Post a Comment