Dev Console showing TypeError on forEach (js)

0

So I’m getting a TypeError for this method when it runs in the web dev console, however I’m not getting any errors in actual code, and can’t seem to find the problem with this. I’m basically doing exactly what it does here, so I can’t figure out what seens to be the problem. Here’s the code:

parse(response) {
    response.forEach(function (customer){ //this gives a TypeError!
        if (customer.LastName) {
            customer.LastName = customer.LastName.charAt(0);
        }
    });

    return response;
}

Response is an array so I feel like it should be working??

Here’s the error message:

Uncaught TypeError: response.forEach is not a function
parse @ customersCollection.es6.js:37
_.extend.set @ backbone.js?0.0.0.0:664
options.success @ backbone.js?0.0.0.0:860
fire @ jquery.js?0.0.0.0:3048
self.fireWith @ jquery.js?0.0.0.0:3160
done @ jquery.js?0.0.0.0:8235
callback @ jquery.js?0.0.0.0:8778

I’m still new to Javascript and callback functions so any input would be great. Thanks a bunch in advance!!

Link: Dev Console showing TypeError on forEach (js)
Source: Stack Jquery

Share.

About Author

Leave A Reply