【问题标题】:I want to know how i look all the names that begin with A [duplicate]我想知道我如何看待所有以 A 开头的名字 [重复]
【发布时间】:2015-07-18 10:20:15
【问题描述】:

我想知道我如何看待所有以 A 或 B 开头的名字或类似的例子,我有 David Daniel Jose Alejandro,我只想要以 A 开头的名字。有人可以告诉我。 名称 = 以 A 开头 现在清楚我需要什么了吗?

【问题讨论】:

  • 所有的名字在哪里?在数组中?这与 cookie 有什么关系?
  • 在表格或类似的东西中,我只想知道如何创建条件来查看以特定字母开头的名称
  • 我刚刚写了这个,现在它已经关闭了,但我还是会在这里发布: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; } 这是未经测试的,但我认为它应该可以工作。只需使用getAllByLetter(names,'a')
  • 'table' 是 full.name 但我使用 getAllByLetter(full.name,'a') 并且不工作

标签: javascript string


【解决方案1】:

我想你正在寻找这个:

How to get first character of string?

基本上

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

【讨论】:

    猜你喜欢
    • 2022-12-01
    • 1970-01-01
    • 2015-06-29
    • 2018-06-13
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 2021-05-25
    • 2021-03-04
    相关资源
    最近更新 更多