简体   繁体   English

如何让字符串以小写字母开头?

[英]how can i get the string start with lowercase?

 const arryStudent = [{ name: 'faizan', rollNo: 11, marks: 80 }, { name: 'irfan', rollNo: 12, marks: 75 }, { name: 'Abdullah', rollNo: 13, marks: 69 }, { name: 'Asad', rollNo: 23, marks: 71 }, { name: 'ali', rollNo: 14, marks: 71 } ]; const startsWithA = arryStudent.filter((student) => student.name.startsWith('A')); console.log(startsWithA);

This is the way you can check..这是你可以检查的方式..

    arryStudent.forEach(element => {
        if (element.name[0] == element.name[0].toLowerCase()){
         console.log(`${element.name} startswith lower case`);
      }
        if (element.name[0] == element.name[0].toUpperCase()){
         console.log(`${element.name} startswith Upper case`);
      }

    }); 

Write a function that filters out the names based on the letter.写一个 function 根据字母过滤掉名字。

 const students=[{name:"faizan",rollNo:11,marks:80},{name:"irfan",rollNo:12,marks:75},{name:"Abdullah",rollNo:13,marks:69},{name:"Asad",rollNo:23,marks:71},{name:"ali",rollNo:14,marks:71}]; // Write a function that accepts the data, // and the letter you're looking for function find(arr, letter) { // Always lowercase the letter const lc = letter.toLowerCase(); // And then filter out the names that match return arr.filter(student => { return student.name.toLowerCase().startsWith(lc); }); } console.log(find(students, 'A'));

You can use startsWith twice like:您可以使用两次startsWith

 const arryStudent = [{ name: 'faizan', rollNo: 11, marks: 80 }, { name: 'irfan', rollNo: 12, marks: 75 }, { name: 'Abdullah', rollNo: 13, marks: 69 }, { name: 'Asad', rollNo: 23, marks: 71 }, { name: 'ali', rollNo: 14, marks: 71 } ]; const startsWithA = arryStudent.filter((student) => student.name.startsWith('A') || student.name.startsWith('a')); console.log(startsWithA);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 JavaScript 测试字符串中的字母是大写还是小写? - How can I test if a letter in a string is uppercase or lowercase using JavaScript? 如何获取文本节点内字符串的起始偏移量? - How can I get start offset of a string inside text node? 如何从字符串开头获取与RegEx的匹配 - How can I get one match with RegEx from start of string 如何创建一个 aphabets 数组,从中提取随机的大写和小写字母? - How can I create an aphabets array from which random uppercase & lowercase alphabets get pulled? 如何使用 javaScript 创建一个 function (countMs),它采用字符串文本并返回其中的字母数量(大写和小写) - how can I Create a function (countMs) that takes a string text and returns the number of letters'm'in it(both uppercase and lowercase)using javaScript 如何将某些部分更改为小写且不带空格? - How can I change certain parts to lowercase and without spaces? 如何使用仅小写字母的验证模式 - How can I use lowercase letters only validation pattern 如何使我的搜索表单使用大写和小写 - How can I make my search form work with uppercase and lowercase 在 JMeter 和 BeanShell 中,如何使变量小写? - In JMeter and BeanShell, how can I make a variable lowercase? 如何使javascript匹配字符串的开头? - How can I make javascript match the start of a string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM