본문 바로가기

JavaScript/javascript 기초 공부하기

every, some, Set, startsWith, includes, endsWidth

반응형

every

 

렌더링시에 조건을 만족하는 경우에 자주쓰는 every

 

모든 조건을 충족해야 true가 반환된다 

const arr = [2, 3, 4];

const isBiggerThenOne = arr.every(key => key>1);

console.log(isBiggerThenOne); // true

 

some

 

하나의 조건만 충족해도 true를 반환한다 

 

const arr = [1, 2, 0, -1, -2];

const res = arr.some((key) => key < 0);
console.log(res); // true

 

 

 

Set

Set은 중복되지 않은 자료구조이다,

const test = new Set();

test.add(1);
test.add(1);
test.add(2);
test.add(2);
test.add(3);

for (const item of test) { //Set은 iteration으로 for of를 활용해서 추출해 낸다 
    console.log(item);
}

//1, 2, 3


//2가 존재하는지 확인
const ret = test.has(2);
console.log(ret); // true

startsWidth = 해당문자로 시작

includes = 포함

endsWidth = 해당문자로 끝이나는지

let string = 'node.js';
let isStart = string.startsWith('n');
let isInclude = string.includes('node');
let iusEnd = string.endsWith('s');
console.log(isStart);
console.log(isInclude);
console.log(iusEnd);

 

 

 

반응형

'JavaScript > javascript 기초 공부하기' 카테고리의 다른 글

javascript 객체지향을 위한 class 생성하기  (0) 2020.05.02
커링 함수 currying function  (0) 2020.05.02
async / await  (0) 2020.01.26
callback hell, Promise  (0) 2020.01.25
spread, rest 문법  (0) 2020.01.25