코딩/javascript (2) 썸네일형 리스트형 🖐forEach / for of / for in 차이점 ⭐forEach forEach는 array를 순회하는 함수이며, 인자로 함수를 받아 각 배열 요소에 해당 함수를 적용한다. const num = [123,456,789,10]; num.forEach((number) => { console.log(number) // 123,456,789,10 }); ⭐for of (es6) for of는 array만 사용 가능한 forEach와는 달리 array와 obj 모두 사용가능하다. (순회 가능한(iterable) 객체에 사용이 가능하다.) const weather = ["sunny","clear"] for(let sky of weather){ console.log(sky) // sunny , clear } ⭐for in for in은 모든 객체에 사용이 가능하다... 📕ES6 주요 문법 정리 ⭐ 새로 추가된 string 메서드 startsWith( ) : string의 시작이 일치하는 문자열이 있는지 판단한다. endWith( ) : string의 끝이 일치하는 문자열이 있는지 판단한다. includes( ) : 해당 문자열이 포함되어 있는지 판단한다. const weather = "The weather is sunny today."; weather.startsWith("The"); // true weather.endsWith("today"); // true weather.includes("is"); // true weather.includes("rain"); // false ⭐ shorthand property names obj의 key와 value의 이름이 동일하다면, 축약해서 이름 하나.. 이전 1 다음