Single Record Mapping

Overview


A map (single record map) is a transformation that creates a new object (record) from each object in an array. The transformation depends only on one object, and not details of the whole array.

Single record maps are accomplisehd using the map function on the array. The map function takes another function as an input, which specifies how to transform the given object to the new desired object.
Examples
This example takes an array of objects, each with a value on it, and returns new objects with the value and a new property called "twice" which is just 2 times the value.


let data = [{value:1},{value:2},{value:3},{value:4},{value:5}];
let results = data.map(item=>{
  return {
    value:item.value,
    twice:2*item.value
  }
});
				
Try it!

This example utilizes arrow functions to simplify the syntax.

Contents