Reputation: 1089
I'm building custom remote methods to Loopback. When I'm doing query and trying to forward relations to own function where is forEach. Realtion list causes error relations.forEach is not a function
Example:
return Api.find({include: ['relations']}).then(result => {
return myFunction(result.relations)
})
myFunction(relations) {relations.forEach(obj => {console.log(obj)})};
How I can convert List object to javascript array. toJSON() not working for List objects
Upvotes: 0
Views: 553
Reputation: 2675
Have you tried to do the JSON conversion directly on your result? Like:
return Api.find({include: ['relations']}).then(result => {
result = result.toJSON(); //add this line
return myFunction(result.relations)
})
myFunction(relations) {relations.forEach(obj => {console.log(obj)})};
Upvotes: 1
Reputation: 6910
if you need json string from an array of objects, then:
var jsonString=JSON.stringify({relations:relations});
Upvotes: 0