0

i have the following code:

let str = ("George Washington", "Abe Lincoln", "Kanye West");

function fullNameArgsToObject() {
  let str = "";
  let obj = {};

  for (let i = 0; i < arguments.length; i++) {
    console.log(arguments[i], "flag");
    str = arguments[i]
  }
}

fullNameArgsToObject(str);

the output of this is: "Kanye West flag" but why is it only returning Kanye West? why is not printing the first two strings? im kind of new with js, thanks!

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Try doing `console.log(str);` – Barmar Aug 10 '21 at 08:00
  • What do you think `str` is? – Zsolt Meszaros Aug 10 '21 at 08:03
  • `let str = ("George Washington", "Abe Lincoln", "Kanye West");` would set `str` to `'Kanye West'` – AdityaParab Aug 10 '21 at 08:04
  • Instead of a tuple use an array: change the let str = ("George Washington", "Abe Lincoln", "Kanye West"); to let str = ["George Washington", "Abe Lincoln", "Kanye West"]; Additionally use parameters in the function declaration: function fullNameArgsToObject(strs) { let str = ""; let obj = {}; for (let i = 0; i < strs.length; i++) { console.log(strs[i], "flag"); str = strs[i] } } – Hidi Eric Aug 10 '21 at 08:05

0 Answers0