如果第一个字符串以特定第二个字符串开头,则返回 TRUE JavaScript
我们需要编写一个 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP