如果第一个字符串以特定的第二个字符串开头,则返回TRUE
我们需要编写一个包含两个字符串的JavaScript函数,并检查第一个字符串是否以第二个字符串开头
例如-
If the two strings are: “Disaster management report” “Disas” Then our function should return true
让我们为该函数编写代码-
示例
const first = 'The game is on';
const second = 'The';
const startsWith = (first, second) => {
const { length } = second;
const { length: l } = first;
const sub = first.substr(0, length);
return sub === second;
};
console.log(startsWith(first, second));输出结果
控制台中的输出将为-
true
热门推荐
8 敏字的祝福语简短
10 诗意新婚祝福语高级简短
11 友谊诗歌祝福语大全简短
12 生日哥哥祝福语简短独特
13 中班入学祝福语简短大全
14 妈妈生日祝福语简短温暖
15 新婚祝福语简短十六字
16 2026新年祝福语简短语
17 祝福语简短创意闺蜜
18 麻辣拌店祝福语简短