Good, I am trying to set the forEach method for the Array class in javascript, to use it in a function that adds each element to a string. The object is a NodeofList, but I can not do it:
NodeofList<Element>.forEach=funcion(){};
The code that I have is the following:
Array.forEach += function (callback) {
for (var i = 0; i < this.length; i++)
callback(this[i], i, this);
};
And here is where I try to use it:
function funcionxml() {
var mixml;
var stringaMostrar = " ";//(en realidad esta variable la tengo como global)
if (mipeticion.readyState == 4 && mipeticion.status == 200) {
mixml = mipeticion.responseXML;
var arrayPersonas = mixml.getElementsByTagName("persona");
arrayPersonas.forEach(function (element, index, lista) {
stringaMostrar += element.getElementsByTagName("nombre")[0].firstChild.nodeValue + " " + element.getElementsByTagName("apellidos")[0].firstChild.nodeValue + "\n";
});
document.getElementById("xml").innerHTML = stringaMostrar;
}
}
The error I receive is: arrayPersonas.forEach is not a function.