Angular 2 with Array.include and Object.entries

1 min readApr 4, 2017

Angular-cli generates tsconfig.conf that does support Object.entries and Array.include methods with typescript. In order to start working with these functions tsconfig.conf lib should be modified to include “es2017.object”, “es2016.array.include”.

{
"compilerOptions": {
....
"lib": ["es6", "dom", "es2017.object", "es2016.array.include"],
....
}
}

Array.include

After this change you can change all your lodash array_.includes to standard es6 includes

let groupIds = [1,2,4];
let groups = [{id:1,name:'A'}, {id:2,name:'B}, {id:2222, name'C'}];
let groups= groups.filter(({id}) => groupIds.includes(id));

Object.entries

Object.entries provides access to key and value of an object as a key,value pair. The code that uses Object.keys and retrieves key’s value from the object like that:

Object.keys(inputs).forEach(key => {
let value = inputs[key];
console.log(`key is ${key} and value is ${value}`);
});

can be changed to more concise form with Object.entries

Object.entries(inputs).forEach(([key, value]) => {
console.log(`key is ${key} and value is ${value}`);
});

--

--

Julia Passynkova
Julia Passynkova

Written by Julia Passynkova

Front-End developer working as an independent contractor with Angular and React in Toronto, Canada.

Responses (2)