All stacks / Intents / Character at index Also written as index of character
Repeat and Character Access JS · Strings syntax Copy
str.repeat(count)
str.at(index)example Copy
const border = "=" .repeat(30 );
console.log(border);
const word = "JavaScript" ;
console.log(word.at(0 ));
console.log(word.at(-1 )); Note at() supports negative indices to count from the end. Bracket notation str[-1] returns undefined, not the last character.
syntax Copy
POSITION(substring IN string )
STRPOS(string , substring) example Copy
SELECT
email,
POSITION('@' IN email) AS at_position,
SUBSTRING(email FROM POSITION('@' IN email) + 1 ) AS domain
FROM users;output
-- email | at_position | domain
-- [email protected] | 6 | example.comNote Returns the 1-based position of the first occurrence. Returns 0 if not found (not -1 like most programming languages). MySQL uses LOCATE(substring, string) which has the arguments in reverse order.
Related tasks