Bits of code

Reduce array to objects in that array

  let array = [
  { v1: "v1", v2: "v2" },
  { v1: "v1", v2: "v2" },
  { v1: "v1", v2: "v2" },
];
let result = array.reduce((currentArry, elementOfTheArry, Index) => {
  currentArry.push(elementOfTheArry.v1);
  return currentArry; // *********  Important ******
}, []);

console.log(result) // result = [ 'v1', 'v1', 'v1' ]

Coerce string into a number

Backticks reference

Backticks (`) are used to define template literals. Template literals are a new feature in ECMAScript 6 to make working with strings easier.

Features:

  • we can interpolate any kind of expression in the template literals.

  • They can be multi-line.

Note: we can easily use single quotes (') and double quotes (") inside the backticks (`).

Example:

To interpolate the variables or expression we can use the ${expression} notation for that.

Multi-line strings means that you no longer have to use \n for new lines anymore.

Example:

Output:

Dynamic Object

Array intersection

Array Difference

Symmetrical Difference

Union

find duplicates

Javascript ES6/ES5 find in array and change

the map loops over each item in the items array and checks if that item has id the same as the id of the item in the const variable. If it finds one, it maps that item which is x to item which is the one in the const variable, otherwise it keeps the same element x in the items array.

Given a changed object and an array:

Update the array with the new object by iterating over the array:

Check if Object has a property

Check if an object have a specific property

ParseJwt without lib

Last updated

Was this helpful?