Amongst the new features released with the new ES6 standard in Javascript are a bounty of new built-in methods. These new methods aim to simplify and standardize some familiar scenarios that developers encounter when working with JS data types like Numbers, Strings, Object and Arrays.

One of the goals of ES6 was to make coding in JS cleaner and more concise, let’s take a look at how these new methods help move us towards that goal.

In each code snippet below you will see:

//ES6 — this is the new ES6 implementation of the feature //ES5 — this is the ES5 equivalent(if there is one) of the new ES6 implementation

If you like this post check our last post on JS ES6 Proxies

Object Property Assignment

When working with objects you often need to combine 2 or more objects. The new Object.assign() function provides a clean method for doing just that.

Object Merge

Object.assign merge

We start off with 3 Objects on lines 2–4 with the intention of combining them into the destination Object. In ES5 you had to loop through and independently append the values to the destination object. In ES6 you can do this with a single line of code(line 15).

What happens when you merge objects with same properties you ask? Let’s see.

Merge With Same Properties

You can also use Object.assign() to clone Objects.

Object Clone

Object.assign clone

Array Element Finding

Commonly when working with Arrays you will want to find an element OR the index of an element in an Array. ES6 provides 2 new Array methods find() and findIndex() to do this. It is important to note that find() will return the FIRST element in the Array that satisfies the provided testing function. Let’s take a look at these new ES6 functions and their ES5 equivalents(there is no ES5 equivalent for findIndex()).