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"; }Este código combina el nombre completo y el apellido de una persona en función de su número de identificación.
console.log (FullName("1", true));Cuando utilicé console.log para verificar si el nombre completo está escrito correctamente, descubrí que hay un espacio entre las comillas y la primera letra, como este: "Alexandre Despatie". ¿Alguien puede ayudarme a eliminar el espacio no deseado?
usar .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"; }