Using the reduce array helper in ES6

ES6 comes with a number of helper methods that can be applied to arrays. One of these is called reduce which can be used in aggregation scenarios where we in each loop need to use the result of the previous loop. Reduce is certainly a bit more difficult to grasp and use than the other array helpers introduced in ES6. If you’re familiar with C# and LINQ then the reduce array helper is similar to the Aggregate LINQ extension method.

Let’s see an example.

Read more of this post

Advertisement

Destructuring in ES6

Destructuring in ES6 is about pulling out certain properties from objects into other variables. It can also be used to extract values from arrays into variables.

Here’s an example object:

let customer = {
  name: 'Great Customer Inc',
  address: 'Los Angeles'
}

Here’s how we can pull out the name and address properties from the customer with destructuring:

Read more of this post

Using the every array helper in ES6

ES6 comes with a number of helper methods that can be applied to arrays. One of these is called every which returns true if all elements in an array fulfil the specified condition and false otherwise. If you’re familiar with C# and LINQ then the every function is very similar to the All LINQ extension method.

Let’s see an example.

Read more of this post

Using the find array helper in ES6

ES6 comes with a number of helper methods that can be applied to arrays. One of these is called find which finds the first matching element in an array based on a condition. If you’re familiar with C# and LINQ then the find function is very similar to the Where/Select and FirstOrDefault LINQ extension methods.

Let’s see an example.

Read more of this post

Enhanced object literals in ES6

ES6 comes with a couple of syntactic enhancements regarding object literals. These enhancements do not add new functionality to JavaScript. Instead, they are syntactic sugar that make it possible to write a little less code.

Here’s a simple example of a “normal” JSON object returned without these enhancements:

Read more of this post

Writing classes in ES6

ES6 has introduced classes and object inheritance. These are welcome additions since they provide a more convenient way to build object-oriented code than before with functions and prototypes.

Unsurprisingly the keyword to build a class is “class”. Here’s the most simple class with a default empty constructor:

Read more of this post

Using the filter array helper in ES6

ES6 comes with a number of helper methods that can be applied to arrays. One of these is called filter which can filter out various elements from an array and add those elements to a new array. If you’re familiar with C# and LINQ then the filter function is very similar to the Where and ToList LINQ extension methods.

Let’s see an example:

Read more of this post

Default function arguments in ES6

JavaScript has been extended with default function arguments in ES6. They work much like in other languages such as C#.

Here’s an example with a two arguments, one compulsory, one default:

Read more of this post

For-of loops in ES6

ES6 has a new iterator that behaves like for-each loops in C# or Java. In ES6 it’s called a for-of loop. For-each / for-of loops come in very handy when looping through collections.

Here’s a short example:

Read more of this post

Using the map array helper in ES6

ES6 comes with a number of helper methods that can be applied to arrays. One of these is called map which can transform each element in an array and produce a new array from those transformed elements. If you’re familiar with C# and LINQ then the map function is very similar to the Select LINQ extension method.

Here’s an example to iterate through an array of integers and collect their squared values into a new array:

Read more of this post

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

Bite-size insight on Cyber Security for the not too technical.

%d bloggers like this: