I cannot for the life of me figure out the difference between these two blocks of code:
var text = [];
$(".article-text p").each(function() {
text.push( $(this).text() );
});
And
var text = $('.article-text p').map(function() {
return $(this).text();
});
They look to me like they produce the same exact output when tested in console on the following page. However, the first one can be run by JSON.stringify, and the second cannot.
My error message in the crawler says
Error invoking user-provided 'pageFunction': Error: TypeError: JSON.stringify cannot serialize cyclic structures.
My error message in console says:
Uncaught DOMException: Blocked a frame with origin "http://yaledailynews.com" from accessing a cross-origin frame. at JSON.stringify () at :1:6
When I compare the two objects, they look exactly the same, except that the second has a context property. I have deleted this property but the errors still remain.
$.map()returns a jQuery object: "As the return value is a jQuery object, which contains an array, it's very common to call .get() on the result to work with a basic array."