Monday, 10 April 2017

NodeJS: break Array.some loop [duplicate]

This question already has an answer here:

I have the following function that receives a JSON array templates and returns a JSON object.

The code executes the console.log. However, it always returns the null at the end of the function. Any ideas?

function getTemplate(templates, myId) {
  Object.keys(templates).some(obj => {
    if (templates[obj].id === myId) {
      console.log('HELLO');
      return templates[obj];
    }
  });
  return null;
}

template array

[
    {
        "id": 80,
        "name": "template 1"
    },
    {
        "id": 81,
        "name": "template 2"
    }
]

However, it always returns null.



via Arturo

No comments:

Post a Comment