0

I want to know how i look all the names that begin with A or B or something like that example i have David Daniel Jose Alejandro and i only want that names that begin with the A. can someone tell me. name = start with A Is it now clear what I need?

  • All the names where? In an array? What does this have to do with cookies? – Barmar May 07 '15 at 17:28
  • In a table or something like that just i wanna know how i make a condition to look the names that begin with a specific letter – user3384175 May 07 '15 at 17:31
  • I just wrote this, now it's closed, but I will post it here anyway: `var names = ['Alex','James','Robert','Andrea','Samantha','Barnaby']; function getAllByLetter(list, letter) { x = []; for (var i = 0; i < list.length; i++) { if (list[i].charAt(0).toLowerCase() == letter.toLowerCase()) { x.push(list[i]); } } return x; }` This is untested, but I think it should work. simply use `getAllByLetter(names,'a')` – Dendromaniac May 07 '15 at 17:36
  • the 'table' is full.name but i use getAllByLetter(full.name,'a') and is not working – user3384175 May 07 '15 at 17:45

1 Answers1

1

I think you are looking for this:

How to get first character of string?

Basically

if (yourstring.charAt(0) == 'A'){
  *your desired code*
}
Community
  • 1
  • 1