0

I am new to programming and i would like to know what is the utility of the 'acc' parameter in the find function in javascript. what is that parameter used for? it is used for taking place of accounts object? who does this parameter belong to? i know it is called a local variable but what is inside this local variable? what is the functionality of it ?

btnLogin.addEventListener('click', function (e) {
  //Prevent form from submitting
  e.preventDefault();

  currentAccount = accounts.find(
    acc => acc.username === inputLoginUsername.value
  );
  console.log(currentAccount);
});
const account1 = {
  owner: 'Jonas Schmedtmann',
  movements: [200, 450, -400, 3000, -650, -130, 70, 1300],
  interestRate: 1.2, // %
  pin: 1111,
};

const account2 = {
  owner: 'Jessica Davis',
  movements: [5000, 3400, -150, -790, -3210, -1000, 8500, -30],
  interestRate: 1.5,
  pin: 2222,
};

const account3 = {
  owner: 'Steven Thomas Williams',
  movements: [200, -200, 340, -300, -20, 50, 400, -460],
  interestRate: 0.7,
  pin: 3333,
};

const account4 = {
  owner: 'Sarah Smith',
  movements: [430, 1000, 700, 50, 90],
  interestRate: 1,
  pin: 4444,
};

const accounts = [account1, account2, account3, account4];
Davyyd
  • 1
  • 2

1 Answers1

0

Pretty much it’s a symbol representing the current iteration ion of the data being searched. You could call it anything and it just works.

acc is likely short for account in this example.

Think of it like “for each account in accounts object, check to see if account username matches the data on the other side of ===“

Ohh also, everything inside the () is a function. Acc would be the parameter of another function inside find.

Some good documentation to get more examples.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

James
  • 35
  • 6