JS exercise to process an array of animals
I do spot a minor "C# accent" :)

Unless you are dealing with very unruly data, an idiomatic approach would likely drop most of the special-case checks and use map instead of the for-loop:

// This function could even be removed, depending on the larger details of your code
function getAnimals(data) {
  return data.map(getAnimal);
}

function getAnimal(item) {
  return {
    id: item.id,
    type: item.type,
    name: item.name,
  };
}


If the source array may contain null-ey items, you could filter them out beforehand, instead of after attempting to process them:

function getAnimals(data) {
  return data
    .filter(Boolean)
    .map(getAnimal);
}


(null or undefined will evaluate to false in a boolean context.)

If you have a utility library like Lodash on hand, you could use a function like pick to further simplify things:

const getAnimal = item =&gt; _.pick(item, ['id', 'type', 'name']);


Otherwise, on a more general scale, most JS code tends to omit explicit null/undefined checks. Let the code throw an error if necessary, otherwise fix whatever is calling your function, eg. by filtering. There's a place for such checks, but in JS it's usually not in every function.


  What I'm really talking about is the way the code is structured. For example, as an "old school" C# developer, I like creating variables and assigning my data to them and cleanly returning them in my methods.


I don't think the code you've provided here merits any temporary variables. Idiomatically, it's a single function applied via Array#map.



Minor syntax things


Your functions are currently in the global namespace, because JS permits variables with no qualifiers as implicit globals. Prefix them with const or let to explicitly make them variables, or use function when possible since it plays nicer with hoisting:

const processArray = (myArray) =&gt; {...
// or, as above
function processArray(myArray) {...

Many people omit the braces around the single argument of an arrow function. It's optional, but reads slightly cleaner:

const processArray = myArray =&gt; {...

myArray is a toy name, I am assuming this is a toy example
Always use === for comparisons, which you do, unless you want to compare against both null and undefined, which you do, in which case you can do myArray == null. To go a bit further, your first conditional would more simply be written:

if (!myArray || !myArray.length) {


since null and undefined are both "falsey", and so is a zero length.


Essentially: your code works fine -- but it could be a lot shorter.