热门
const text = 'Hello, World!'; const containsHello = text.includes('Hello'); // true
charAt
charCodeAt
const text = 'JavaScript'; const char = text.charAt(4); // 'S' const charCode = text.charCodeAt(0); // 74 (字符 'J' 的Unicode编码)
const text = 'abcdef'; const reversedText = text.split('').reverse().join(''); // 'fedcba'
const fruits = ['apple', 'banana', 'cherry']; const joinedString = fruits.join(', '); // 'apple, banana, cherry'
const text = 'abczxy'; const maxChar = Math.max(...text); // 'z' const minChar = Math.min(...text); // 'a'
const number = '42'; const paddedNumber = number.padStart(5, '0'); // '00042'
const unsorted = 'cbadfe'; const sorted = [...unsorted].sort().join(''); // 'abcdef'
const longText = 'This is a long text that needs to be split into chunks.'; const chunkSize = 10; const chunks = []; for (let i = 0; i < longText.length; i += chunkSize) { chunks.push(longText.slice(i, i + chunkSize)); }
const email = 'example@email.com'; const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); // true
const sentence = 'This is a sample sentence'; const words = sentence.split(/\s+/); // ['This', 'is', 'a', 'sample', 'sentence']