DEV Community

Jack 'eXit' Whitter-Jones
Jack 'eXit' Whitter-Jones

Posted on • Updated on

Week 3 - Array of Objects

The modern web functions predominately on the use of Application Programming Interfaces (APIs). Many of the APIs return data by passing an array of objects between one another.

This weeks worth of study has been reviewing the LearnJavaScript.online has focused on the management of API data that is in the form of an Array of Objects.

What Was Learnt

This weeks worth of learning built on the array functions in the previous week, but with the added complexity of managing an array of object coupled with optional chaining.

Of interest in this week was working with objects simulated against the Twitter API, for example:

const tweets = [
    {
        id: 1,
        message: "Week 2 - JavaScript and Beyond...",
        user: {
            handle: "jack_wj"
        },
        stats: {
            likes: 1,
            retweets: 1
        }
    },
    {
        id: 2,
        message: "Week 3 - Array of Objects",
        user: {
            handle: "jack_wj"
        },
        stats: {
            likes: 1,
            retweets: 1
        }
    }
];

const socialScore = tweets.reduce((total, tweet) => {
    return total + tweet.stats.likes + tweet.stats.retweets;
}, 0);
console.log(socialScore); // 4

const messages = tweets.map(tweet => tweet.message); // [ 'Week 2 - JavaScript and Beyond...', 'Week 3 - Array of Objects' ]
console.log(messages);
Enter fullscreen mode Exit fullscreen mode

One way to improve the visualisation of the objects that are being managed within the array is to change the "current" variable name that is typical used within the reduce function, but instead to refer to it as its singular variable name, in this instance "tweet".

So far this week has begun to introduce me to how APIs manage and send data, which will help build into frameworks such as Express and React.

Resource Review

This week has hasn't had as much progress as previous week, however, the material has begun to gently introduce how APIs manage data in a succinct way that has built off previous weeks.

It has also begun to introduce more intermediate content, such as try...catch, optional chaining, and nullish coalescing.

The LearnJavaScript.online resource has definitely increased in complexity but has managed to maintain its stability in ease of use and structured approach to learning.

Retrospective

  • I believe with the increase in complexity, it might be worth beginning to look at React or Express to help tie knowledge that is being learnt from LearnJavaScript.online to other content to further compound the lessons that are being learnt. However, this will need to be thought out before committing to it.

Sign Off

Until next week!

~ Jack/eXit

Discussion (0)