JavaScript Higher Order Functions & Arrays

In this video we will look at some of the very powerful higher order functions and working with arrays. We will look at forEach, map, filter, reduce and sort.



CODE: JSFiddle

💖 BECOME A PATRON: Show support & get perks!

VISIT MY WEBISTE: Check Out My Udemy Courses


34 thoughts on “JavaScript Higher Order Functions & Arrays

  1. Interesting how the language is maturing, the function equivalent => is somewhat similar to if else ? : . I guess once you are in the know it’s ok, but does tend to obfuscate what the intent is relative to the long form. IMHO ( from a newb coming from the embedded C world.) . I find the keyword automation to be daunting. Thanks for creating these videos Brad. They are exceptionally well done.

  2. HI! I know its been a loong time since this video is uploaded but…

    Anyway that with filter i can return an specifici field?
    I mean for example
    Filter companies with category Retail give as result -> {name:blabla , category: bla bla, start :bla bla, end:bla bla}
    i want to filter for retail but the result is just the name
    I know i can do it filtering and the mapping it but want to know if we can just with filter

  3. You could make a whole database management system in javascript using this – if only there was a nice way for the client browser to seamlessly persist data to a file, that was standard and didn't involve using some other feature like a server or node.js.

    Also, JSON is great but you have to keep repeating the field names for each line/record of data. That's an inefficient use of dataspace. why not have something like a field array: an array of arrays where the first array could be field names like so:

    ['name', 'age'],
    ['mike', 29],
    ['Jane', 25],
    ['Jerry', 35]

    This is a more efficient use of dataspace than:

    {name: 'mike', age: 29},
    {name: 'Jane', age: 25},
    {name: 'Jerry', age: 35}

    If you're worried about the field names getting in the way of sorting then you can do this:

    fields: ['name', 'age'],
    rows: [
    ['mike, 26],
    ['Jane', 25],
    ['Jerry', 35]

    which would allow you to use your higher order functions on the rows property without the field names getting in your way. Then you can create a data access function like so:

    function fieldDataAt (fieldArray, fieldName, index) {
    let fieldPosition = fieldArray.fields.indexOf(fieldName);
    return fieldArray.rows[index][fieldPosition];

    You can even create a field array wrapper object that accepts a fieldarray data object as an argument in the constructor and uses special functions that make data access and manipulation easy.

Leave a Reply

Your email address will not be published. Required fields are marked *