0

This code is causing an error in the developer console:

$scope.AddCandidatesToCompannies = function()
{
    console.table($scope.candidates);
    Object.entries($scope.candidates).forEach(candidate =>
    {
        candidate.jobs.forEach(job =>
        {
            var company_id = job['company_id'];

            Object.entries($scope.companies).forEach(company =>
            {
                if (company['company_id'] == company_id)
                {
                    console.log('match'); 
                };
            });
        });
    });
};   // AddCandidatesToCompannies()

$scope.candidates DOES contain data, and it is an object; it's quite complex, so I won't clutter the question with it, but her is an overview pic

enter image description here

The statement Object.entries($scope.candidates).forEach(candidate => gives

angular.min.js:83 TypeError: Cannot read property 'forEach' of undefined
at mapController.js:138
at Array.forEach ()
at a.$scope.AddCandidatesToCompannies (mapController.js:136)
at $scope.ProcessSearchResults (mapController.js:161)
at C (angular.min.js:91)
at C (angular.min.js:91)
at angular.min.js:92
at h.$eval (angular.min.js:100)
at h.$digest (angular.min.js:98)
at h.$apply (angular.min.js:101)
at f (angular.min.js:66)
at K (angular.min.js:70)
at XMLHttpRequest.y.onreadystatechange (angular.min.js:71)

Can anyone see what I am doing wrongly?

1 Answer 1

1

Object.entries return an arrays in an array with then key, value pairs. Looks like you want to have a function like Object.values($scope.candidates)

Example:

Object.entries($scope.candidates) == [[45,{candidate_id:45}],[46,{candidate_id:46}]]
Object.values($scope.candidates) == [{candidate_id:45}, {candidate_id: 46}]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.