Skip to content
Yasser Moradi edited this page Aug 23, 2015 · 1 revision

Description:

The process of transforming the results of a query is called projection. You can project the results of a query after any filters have been applied to change the type of the collection that is returned. For example, you can select a single property or field from the source data or project multiple properties into an type. You can also add calculations and other operations to the projection to generate information that is based upon the source data but not directly retrieved from it.

Samples:

let employees = [
  { name: "Bob", title: "Senior Developer", salary: 40000 },
  { name: "Sam", title: "Developer", salary: 32000 },
  { name: "Mel", title: "Developer", salary: 29000 },
  { name: "Jim", title: "Junior Developer", salary: 20000 },
];

let names = employees.asEnumerable()
  .select(emp => emp.name)
  .toArray();

console.log("using select method to project name property ...");
for (let index = 0; index < names.length; index++)
  console.log(names[index]);


let salaryIncrease = employees.asEnumerable()
  .select(emp =>
    "Employee : " + emp.name +
    " Salary : " + emp.salary +
    " New salary : " + emp.salary * 1.05)
  .toArray();

console.log("projection with calculation ... ");

for (let index = 0; index < salaryIncrease.length; index++)
  console.log(salaryIncrease[index]);
Clone this wiki locally