//.find(), .findIndex(), includes()
const numbers =[1,2,3,4];
const fruits = ['apple','banana','cherry'];
const a = fruits.find(elem=> /^b/.test(elem)
//B로 시작하는 문자열 찾아서 boolean
)
console.log(a); //banana
const b = fruits.findIndex(elem=>/^c/.test(elem)
//c로 시작하는 문자열 index
)
console.log(b); //2
const c = fruits.includes('apple');
console.log(c); //true
/**text()와 정규식표현
//RegExp.prototype.test()
//패턴이 문자열 내에 존재하는지 여부를 알아보자고할때 사용
const str = 'hello world!';
const result = /^hello/.test(str);
console.log(result); // true
'프론트엔드 공부 > javscript' 카테고리의 다른 글
정적메서드 Object.assign(); 복사와 참조의 차이 (0) | 2021.05.25 |
---|---|
정적 메서드와 정적 프로퍼티 (0) | 2021.05.25 |
map과 forEach 차이 (0) | 2021.05.25 |
number - toFixed,parseInt,parseFloat,Math (0) | 2021.05.21 |
String prototype - indexOf,length,slice,replace,match,trim (0) | 2021.05.21 |