ES6 6

SPREAD (전개구문)

SPREAD 전개 구문을 사용하면 배열이나 문자열과 같이 반복 가능한 문자를 0개 이상의 인수 (함수로 호출할 경우) 또는 요소 (배열 리터럴의 경우)로 확장하여, 0개 이상의 키-값의 쌍으로 객체로 확장 => 즉 변수를 가져가서 풀어해친다. console.log(...[1, 2, 3]) // 1, 2, 3 console.log(...'Hello'); // H e l l o const friends = [1, 2, 3]; const family = ['a', 'b', 'c']; console.log([friends, family]); //[Array(3), Array(3)] console.log([...friends, ...family]); //[..

ES6 2021.03.31

Array.findIndex() 및 array.fill()

Array.findIndex() findIndex() 메서드는 주어진 판별 함수를 만족하는 배열의 첫 번째 요소에 대한 인덱스를 반환 const array1 = [5, 12, 8, 130, 44]; const isLargeNumber = (element) => element > 13; console.log(array1.findIndex(isLargeNumber)); // expected output: 3 Array.fill() fill() 메서드는 배열의 시작 인덱스부터 끝 인덱스의 이전까지 정적인 값 하나로 채움 const array1 = [1, 2, 3, 4]; // fill with 0 from position 2 until position 4 console.log(array1.fill(0, 2, ..

ES6 2021.03.31

Array.of() 및 Array.from()

Array.of() Array.of() 메서드는 인자의 수나 유형에 관계없이 가변 인자를 갖는 새 Array 생성 const items = Array.of("a", "b", "c"); console.log(items); // (3) ["a", "b", "c"] Array.from() Array.from() 메서드는 유사 배열 객체(array-like object)나반복 가능한 객체(iterable object)를 이용해 새 Array 생성 const m = new Map([[1, 2], [2, 4], [4, 8]]); Array.from(m); // [[1, 2], [2, 4], [4, 8]] const mapper = new Map([['1', 'a'], ['2&#3..

ES6 2021.03.31

String 내장객체 활용

String 내장객체 활용 // String.includes() // includes() 메서드는 하나의 문자열이 다른 문자열에 포함되어 있는지를 판별하고, 결과를 true 또는 false 로 반환 const isEmail = email => email.includes("@"); console.log(isEmail("a@b")); //output : true /************************************************************************* */ // String.repeat() // repeat() 메서드는 문자열을 주어진 횟수만큼 반복해 붙인 새로운 문자열을 반환 const number = "123456"; const display = `${"*".r..

ES6 2021.03.23

array 와 arrow function 활용

array 와 arrow function 활용 const email = ["a@a.com", "b@b.com", "c@c.com"]; // array.find() // find() 메서드는 주어진 판별 함수를 만족하는 첫 번째 요소의 값을 반환 // 그런 요소가 없다면 undefined를 반환 // array.includes() // includes() 메서드는 배열이 특정 요소를 포함하고 있는지 판별 // true, false 반환 const findEmail = email.find((item) => item.includes("b.com")); console.log(findEmail); //output: b@b.com /**********************************************..

ES6 2021.03.23