const arrayData = [
  [],
  [
    '',
    '',
    '',
    '',
    'All Sales (non-SDR) "Defend Your Spend" Messaging Certification\r\n(March)'
  ],
  [],
  [
    'First Name',
    'Last Name',
    'Email Address',
    'Role',
    'Session Attendance',
    'Knowledge Check',
    'Deck Build & Talk Track Certification\r\nFeedback Scorecard'
  ],
  [
    'Heather',
    'Adams',
    '[email protected]',
    'Performance Rep',
    'Yes',
    'N/A',
    'N/A'
  ],
  [
    'Sune',
    'Akarri',
    '[email protected]',
    'Account Management',
    'Yes',
    '',
    '88%; PASS'
  ],
  [ 'Saul', 'Alvarez', '[email protected]', 'SDR' ],
  [
    'David',
    'Baranyuk',
    '[email protected]',
    'SDR',
    'N/A',
    'N/A',
    'N/A'
  ],
  [
    'Paul',
    'Boehme',
    '[email protected]',
    'Account Management',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Paddy',
    'Brennan',
    '[email protected]',
    'RSD',
    'No',
    'Pass ',
    '100%; PASS'
  ],
  [
    'Shelbi',
    'Brinkworth',
    '[email protected]',
    'SDR',
    'N/A',
    'N/A',
    'N/A'
  ],
  [
    'Grant',
    'Burchfield',
    '[email protected]',
    'AVP, Partnerships & Alliances',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Jacob',
    'Burkhardt',
    '[email protected]',
    'Mid-Market AE',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Brandon',
    'Campbell',
    '[email protected]',
    'Senior Director, Enterprise Sales',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Rick',
    'Castro',
    '[email protected]',
    'Enterprise RSD',
    'Yes',
    '',
    '75%; PROGRESSING'
  ],
  [ 'Jas', 'Cisneros', '[email protected]', 'SDR' ],
  [
    'Alyssa',
    'Croley',
    '[email protected]',
    'Director, Account Management',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Blayne',
    'Cross',
    '[email protected]',
    'Account Management',
    'No',
    '',
    '88%; PASS'
  ],
  [
    'Jojo',
    'Cush',
    '[email protected]',
    'Account Management',
    'No',
    '',
    '88%; PASS'
  ],
  [
    'Niki',
    'Dal Bello',
    '[email protected]',
    'Enterprise RSD',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Sheena',
    'Davidson',
    '[email protected]',
    'Senior Sales Engineer',
    'N/A'
  ],
  [
    'Krissy',
    'Doerr',
    '[email protected]',
    'SDR',
    'N/A',
    'N/A',
    'N/A'
  ],
  [ 'Eron', 'Eccles', '[email protected]', 'SDR' ],
  [ 'Elise', 'Fischer-Colbrie', '[email protected]', 'SDR' ],
  [
    'Cathie',
    'Frazzini',
    '[email protected]',
    'VP, Enterprise Sales & Partnerships',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Autumn',
    'French',
    '[email protected]',
    'Director, Partnerships & Alliances',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Megan',
    'Gast',
    '[email protected]',
    'Strategic RSD',
    'No',
    '',
    '88%; PASS'
  ],
  [
    'Zach',
    'Hendrix',
    '[email protected]',
    'Strategic RSD',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Steve',
    'Hirsch',
    '[email protected]',
    'Director, Sales',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Devin',
    'Hood',
    '[email protected]',
    'Senior Director, Account Management',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Chase',
    'Howland',
    '[email protected]',
    'Account Management',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Ryan',
    'Huck',
    '[email protected]',
    'Regional Sales Director',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Bill',
    'Hyatt',
    '[email protected]',
    'Senior Director, Enterprise Sales Engineering',
    'N/A'
  ],
  [
    'Alyson',
    'Hyder',
    '[email protected]',
    'Director, Partnerships & Alliances',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Keith',
    'Jellick',
    '[email protected]',
    'Sales Engineer',
    'N/A'
  ],
  [
    'Kerry',
    'Jellick',
    '[email protected]',
    'Mid-Market AE',
    'Yes',
    'Mat Leave',
    'Mat Leave'
  ],
  [ 'Megan', 'Jones', '[email protected]', 'Mid-Market AE', 'Yes' ],
  [
    'Nick',
    'Jones',
    '[email protected]',
    'Senior Account Manager',
    'Yes',
    '',
    '75%; PROGRESSING'
  ],
  [
    'Dave',
    'Juengst',
    '[email protected]',
    'Senior Sales Engineer',
    'N/A'
  ],
  [
    'Jon',
    'Katz',
    '[email protected]',
    'Mid-Market AE',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Neal',
    'Kawesch',
    '[email protected]',
    'Director, Partnerships & Alliances',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Lyle',
    'Kotze',
    '[email protected]',
    'Account Management',
    'Yes',
    '',
    '75%; PROGRESSING'
  ],
  [
    'Keith',
    'Laughner',
    '[email protected]',
    'Director, Sales Development',
    'N/A'
  ],
  [
    'Brandon',
    'McCarty',
    '[email protected]',
    'VP, Sales Engineering',
    'N/A'
  ],
  [
    'Stevin',
    'Miliefsky',
    '[email protected]',
    'SDR',
    'N/A',
    'N/A',
    'N/A'
  ],
  [
    'Emily',
    'Piwowarczyk',
    '[email protected]',
    'Corporate AE',
    'Yes',
    '',
    '75%; PROGRESSING'
  ],
  [
    'Natalia',
    'Podolsky',
    '[email protected]',
    'Mid-Market AE',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Jenna',
    'Riplinger',
    '[email protected]',
    'Account Management',
    'No',
    '',
    '75%; PROGRESSING'
  ],
  [
    'Caitlin',
    'Ristau',
    '[email protected]',
    'Account Management',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Kara',
    'Rohleder',
    '[email protected]',
    'Sales Engineer',
    'N/A'
  ],
  [
    'Kirsten',
    'Sears',
    '[email protected]',
    'Enterprise RSD',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Bethany',
    'Self',
    '[email protected]',
    'Corporate AE',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Steve',
    'Sequeira',
    '[email protected]',
    'Mid-Market AE',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Fred',
    'Sevekow',
    '[email protected]',
    'Strategic RSD',
    'No',
    '',
    '88%; PASS'
  ],
  [
    'Arlington',
    'Shirley',
    '[email protected]',
    'Senior Manager, Sales Development',
    'N/A'
  ],
  [
    'Mariah',
    'Skelton',
    '[email protected]',
    'SDR',
    'N/A',
    'N/A',
    'N/A'
  ],
  [
    'Scott',
    'Sprowls',
    '[email protected]',
    'Director, Partnerships & Alliances',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Suzanna',
    'Thompson',
    '[email protected]',
    'Account Management',
    'No',
    '',
    'EOM Extension'
  ],
  [
    'Nick',
    'Tonello Fidler',
    '[email protected]',
    'RSD',
    'Yes',
    '',
    '100%; PASS'
  ],
  [
    'Christian',
    'Torres',
    '[email protected]',
    'SDR',
    'N/A',
    'N/A',
    'N/A'
  ],
  [
    'Steve',
    'Ward',
    '[email protected]',
    'Director, Account Management',
    'No',
    '',
    '100%; PASS'
  ],
  [
    'Bre',
    'White',
    '[email protected]',
    'Account Management',
    'Yes',
    '',
    '88%; PASS'
  ],
  [
    'Les',
    'Yee',
    '[email protected]',
    'Strategic RSD',
    'No',
    '',
    '88%; PASS'
  ]
]// /const arrayData = [/* ... (the provided data) */];
const headers = arrayData[3];

const headers_Group = arrayData[1].filter((fill) => fill !== '');

const arrayOfObjects = [];

// const data_map = [
//   {Table_Column: 'Day_of_the_week', Google_Sheet_Column: 'Day of this week'},
//   {Table_Column: 'Date_1', Google_Sheet_Column: 'Date'}
//   ]
  
const data_map = [
  {Table_Column: 'First_Name', Google_Sheet_Column: 'First Name'},
  {Table_Column: 'Last_Name', Google_Sheet_Column: 'Last Name'},
  {Table_Column: 'Email_Address', Google_Sheet_Column: 'Email Address'},
  {Table_Column: 'Role', Google_Sheet_Column: 'Role'},
  {Table_Column: 'Session_Attendance', Google_Sheet_Column: 'Session Attendance'},
  {Table_Column: 'Knowledge_Check', Google_Sheet_Column: 'Knowledge Check'},
  {Table_Column: 'Deck_Build_Talk_Track', Google_Sheet_Column: 'Deck Build & Talk Track Certification\r\nFeedback Scorecard'},
  ]
  
for (let i = 4; i < arrayData.length; i++) {
  const rowData = arrayData[i];
  const obj = {};

  // Iterate through the headers and populate the object properties
  for (let j = 0; j < headers.length; j++) {
    // obj[headers[j]] = rowData[j];
     obj[headers[j]] = rowData[j] !== undefined ? rowData[j] : ' ';
  }

  // Add the "Group_Name" key with the specified value
  obj["Group_Name"] = headers_Group[0];

  // Push the object into the resulting array
  arrayOfObjects.push(obj);
}


const dataMapObject = {};
data_map.forEach(item => {
    dataMapObject[item.Google_Sheet_Column] = item.Table_Column; // Map Google_Sheet_Column to Table_Column
});

console.log(dataMapObject)

// Modify the JSON data using the dataMapObject
const modifiedData = arrayOfObjects.map(item => {
    const modifiedItem = {};
    for (const key in item) {
        const mappedKey = dataMapObject[key] || key; // Use the mapped key if available, otherwise keep the original key
        modifiedItem[mappedKey] = item[key];
    }
    return modifiedItem;
});

console.log("modified",modifiedData);


// console.log(arrayOfObjects);



const groupNamesObject = { Group_Name: headers_Group[0] };

// console.log(groupNamesObject);
 

Javascript Online Compiler

Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.

About Javascript

Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.

Key Features

  • Open-source
  • Just-in-time compiled language
  • Embedded along with HTML and makes web pages alive
  • Originally named as LiveScript.
  • Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc.

Syntax help

STDIN Example

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
    console.log("Hello, " + line);
});

variable declaration

KeywordDescriptionScope
varVar is used to declare variables(old way of declaring variables)Function or global scope
letlet is also used to declare variables(new way)Global or block Scope
constconst is used to declare const values. Once the value is assigned, it can not be modifiedGlobal or block Scope

Backtick Strings

Interpolation

let greetings = `Hello ${name}`

Multi line Strings

const msg = `
hello
world!
`

Arrays

An array is a collection of items or values.

Syntax:

let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);

Example:

let mobiles = ["iPhone", "Samsung", "Pixel"];

// accessing an array
console.log(mobiles[0]);

// changing an array element
mobiles[3] = "Nokia";

Arrow functions

Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.

Syntax:

() => expression

Example:

const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
                                    .map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);

De-structuring

Arrays

let [firstName, lastName] = ['Foo', 'Bar']

Objects

let {firstName, lastName} = {
  firstName: 'Foo',
  lastName: 'Bar'
}

rest(...) operator

 const {
    title,
    firstName,
    lastName,
    ...rest
  } = record;

Spread(...) operator

//Object spread
const post = {
  ...options,
  type: "new"
}
//array spread
const users = [
  ...adminUsers,
  ...normalUsers
]

Functions

function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
  console.log(`Hello ${name}!`);
}
 
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar

Loops

1. If:

IF is used to execute a block of code based on a condition.

Syntax

if(condition){
    // code
}

2. If-Else:

Else part is used to execute the block of code when the condition fails.

Syntax

if(condition){
    // code
} else {
    // code
}

3. Switch:

Switch is used to replace nested If-Else statements.

Syntax

switch(condition){
    case 'value1' :
        //code
        [break;]
    case 'value2' :
        //code
        [break;]
    .......
    default :
        //code
        [break;]
}

4. For

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
//code  
} 

5. While

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
  // code 
}  

6. Do-While

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
  // code 
} while (condition); 

Classes

ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.

Syntax:

class className {
  constructor() { ... } //Mandatory Class method
  method1() { ... }
  method2() { ... }
  ...
}

Example:

class Mobile {
  constructor(model) {
    this.name = model;
  }
}

mbl = new Mobile("iPhone");