The object returned from querySelectorAll
is a NodeList
, which is Array- like , yet not an actual array.
Try this to convert to an array:
[].slice.call(document.querySelectorAll("a[href*='somestring']"));
HTMLCollection and NodeList objects do not have a splice
method and do not inherit from Array.prototype
.
Furthermore, you can't simply invoke a splice on them as they're not designed to be modified even though they are Array-like .
First, convert them to a true Array .
var arr = document.querySelectorAll("a[href*='somestring']"); // NodeList
arr = Array.prototype.slice.call(arr); // Array
arr.splice(2, 2); // splicing an Array
document.querySelectorAll("a[href*='somestring']")
return an object not array.
try to convert it to an array:
var arr = document.querySelectorAll("a[href*='somestring']");
var a = [];
for(var i =0;i<arr.length ; i++){
a[i] = arr[i];
}
a.splice()//now you can use a as an array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.