

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return TRUE if the first string starts with a specific second string JavaScript
We are required to write a JavaScript function that takes in two strings and checks whether first string starts with second or not
For example −
If the two strings are: “Disaster management report” “Disas” Then our function should return true
Let's write the code for this function −
Example
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));
Output
The output in the console will be −
true
- Related Questions & Answers
- Is the second string a rotated version of the first string JavaScript
- Return a boolean array which is True where the string element in array starts with prefix in Python
- Find if a string starts and ends with another given string in C++
- Check if a string starts with given word in PHP
- How to check if a string starts with a specified Prefix string in Golang?
- Remove all characters of first string from second JavaScript
- Dynamic Programming: Is second string subsequence of first JavaScript
- Check if a String starts with any of the given prefixes in Java
- How to check if string or a substring of string starts with substring in Python?
- Delete elements in first string which are not in second string in JavaScript
- Python Program to check if a string starts with a substring using regex
- Java Program to check if any String in the list starts with a letter
- Return true or false in a MySQL select if another field contains a string?
- Return index of first repeating character in a string - JavaScript
- Compare and return True if two string Numpy arrays are not equal
Advertisements