VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-mapinto-method/

⇱ Collect.js mapInto() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js mapInto() Method

Last Updated : 26 Nov, 2020

The mapInto() method is used to iterate through the collection elements and instantiate the given class with each element as a constructor.

Syntax:

collect(array).mapInto()

Parameters: The collect() method takes one argument that is converted into the collection and then mapInto() method is applied on it.

Return Value: This method returns the mapped collection elements.

Below example illustrate the mapInto() method in collect.js:

Example 1:

Output:

[
 data { name: 'GFG' },
 data { name: 'Geeks' },
 data { name: 'GeeksforGeeks' }
]

Example 2:

Output:

[
 data {
 name: { 
 name: 'Rahul', 
 dob: '25-10-96', 
 section: 'A', 
 score: 98 
 },
 dob: 0
 },
 data {
 name: { 
 name: 'Aditya', 
 dob: '25-10-96', 
 section: 'B', 
 score: 96 },
 dob: 1
 },
 data {
 name: { 
 name: 'Abhishek', 
 dob: '16-08-94', 
 section: 'A', 
 score: 80 
 },
 dob: 2
 },
 data {
 name: { 
 name: 'Rahul', 
 dob: '19-08-96', 
 section: 'B', 
 score: 77 
 },
 dob: 3
 }
]
Comment
Article Tags: