.count(val)

Description

Count returns the number of occurrences of a substring within a string.

Parameters

Count needs a string value to search for within the original string.

Usage On Strings

str = "aabbccdd"

log str.count("a")
// 2
// returns the number of times "a" appears in the string

log str.count("aa")
// 1
// can also count occurrences of longer substrings

log str.count("x")
// 0
// returns 0 if the substring is not found

Last updated

Was this helpful?