프론트엔드 공부/javscript
정규식표현 + .find(),.findIndex,includes()
maggieH
2021. 5. 25. 15:47
//.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