Home > Net >  remove space between quotation and first letter
remove space between quotation and first letter

Time:11-10

function FullName(id){
  var firstName = getColumn("Olympic Medals", "Athlete First Name");
  var lastName = getColumn("Olympic Medals", "Athlete Last Name");
  var ID = getColumn("Olympic Medals", "id");
  for(var i=0; i<firstName.length; i  ){
    if(ID[i] == id){
      return firstName[i]   " "  lastName[i];
    }
  }
  
  return "Not found";
}

This code combines the full name and last name of a person based on their id number.

console.log (FullName("1", true));

When I used console.log to check whether the full name is correctly written, I found that there is a space between the quotation mark and the first letter, like this: " Alexandre Despatie" .Can anyone help me to remove the unwanted space?

CodePudding user response:

use .trim()

function FullName(id){
  var firstName = getColumn("Olympic Medals", "Athlete First Name");
  var lastName = getColumn("Olympic Medals", "Athlete Last Name");
  var ID = getColumn("Olympic Medals", "id");
  for(var i=0; i<firstName.length; i  ){
    if(ID[i] == id){
      return (firstName[i]   " "  lastName[i]).trim();
    }
  }
  
  return "Not found";
}
  • Related