0

How to find the String Count in a String in JavaScript?

Ex:

https://localhost/public/10e900fe-0470-11eb-93c6-f377ab03a336//

Get the // occurrence count.

0

2 Answers 2

2

var string = "https://localhost/public/10e900fe-0470-11eb-93c6-f377ab03a336//";
console.log((string.match(/\/\//g) || []).length);

You can try below code:

var string = "https://localhost/public/10e900fe-0470-11eb-93c6-f377ab03a336//";
console.log((string.match(/\/\//g) || []).length);
Sign up to request clarification or add additional context in comments.

Comments

2

var a="https://localhost/public/10e900fe-0470-11eb-93c6-f377ab03a336//"
var count= a.split("//").length-1;
console.log(count)

you can find the count by splitting it into an array and find the length of the array

var a="https://localhost/public/10e900fe-0470-11eb-93c6-f377ab03a336//"
var count= a.split("//").length-1; // its 2

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.