문자 1개를 접근할 경우
'dog'.charAt(1) // 'o'
여러 문자를 접근할 때
'Youtube'.substring(1,2) // 'o'
'Youtube'.substring(3,7) // 'tube'
let a = 'a';
let b = 'b';
console.log(a<b); // true return
let a='add', b='b';
console.log(a<b); // true return
a='add', b='ab';
cosole.log(a<b); // false return
'Red Dragon'.indexOf('Red'); // 0 return
'Red Dragon'.indexOf('RedScale'); // -1 return
'Red Dragon'.indexOf('Dragon',0); // 4 return
'Red Dragon'.indexOf('Dragon',4); // 4 return
'Red Dragon'.indexOf('',0); // 9 return
const existInString = (str, search) => {
return str.indexOf(search) !== -1;
}
console.log(existInString('red', 'r')); // true return
console.log(existInString('red', 'b')); // false
const countChar = (str, char) => {
let cnt = 0;
let pos = str.indexOf(char);
while(pos !== -1) {
cnt++;
pos = str.indexOf(char, pos+1);
}
return cnt;
}
let str = "He's my king from this day until his last day";
console.log(countChar(str, 'a')); // 3 return
'Red Dragon'.startsWith('Red'); // true return
'Red Dragon'.endsWith('Dragon'); // true return
'Red Dragon'.startsWith('Dragon'); // false
'Red Dragon'.endsWith('Red'); // false
let test = 'chicken, noodle, soup, broth';
test.split(','); // ['chicken','noodle', 'soup', 'broth']
test = 'soup';
test.split(''); // ['s','o','u','p']
"Wizard of Oz".replace("Wizard","Witch"); // "Witch of Oz" return
let str = 'JavaScript DataStructures';
let n = str.search(/DataStructures/);
console.log(n); // 11 return
let reg = /\d+/;
reg.test("123"); // true return
reg.test("33asd"); // true return
reg.test("5asdasd"); // true return
reg.test("asdasd"); // false return
let reg = /^\d+$/;
reg.test("123"); // true return
reg.test("33asd"); // false return
reg.test("a"); // false return
let reg = /^[0-9]*.[0-9]*[1-9]+$/;
reg.test("12") // true return
reg.test("12.2") // true return
let reg = /[a-zA-Z0=9]/;
reg.test("somethingELSE"); // true return
reg.test("112") // true return
reg.test("112a") // true return
reg.test("^"); // false return
let uri = "http://your.domain/product.aspx?category=4&product_id=2140&query=lcd+tv";
let queryString = {};
uri.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0,$1,$2,$3){ queryString[$1] = $3;}
)
console.log('ID: ' + queryString['product_id']); // ID:2140 return
console.log('Name:' + queryString['product_name']); // Name: undefined return
console.log('Category:' + queryString['category']); // Category: 4 return