Destructuring Array 123456789// Destructuringlet data = ["crong", "honux", "jk", "jinny"];//일반적으로 구하는 방법// let jisu = data[0];// let jung = data[2]; let [jisu, , jung] = data;console.log(jisu, jung); Colored by Color Scriptercs> "crong""jk" Object 1234567891011121314let obj = { name : "crong", addres : "Korea", age : 20} // name, age 출력//let {name, age} = obj;//console.log(name, age); // 이름을 변경하..
Front-End/JavaScript 검색 결과
간단한 객체 생성 개선된 Object 선언방법 123456789101112131415161718192021222324function getObj() { const name = "crong"; const getName = function() { return name; } const setName = function(newname) { name = newname; } const printName = function() { console.log(name); } return { getName : getName, setName : setName }} var obj = getObj();console.log(obj.getName());cs>"crong" 매번 Object 리터럴형태인 위와 같이 사용할 경우 복잡하다...
from Method 로 진짜 배열 만들기 1234567891011121314// ES6 from method function addMark() { let newData = []; for(let i = 0 ; i ["1!!", "2!!", "3!!", "4!!", "5!!"] JavaScript 내부에 있는 arguments1. 함수에 전달된 인수에 해당하는 Array 형태의 객체이다.2. 해당 객체는 모든 함수 내에서 이용가능한 지역변수이다. 3. 해당 객체는 Array 와 비슷하지만 Array 는 아니다. length 를 제외하고는 Array 속성이 없기 때문이다. 그러나 실제 Array 로 변환될 수 있다. 4. 가변적인 Parameter 가 들어오는 경우 주로 사용한다. (아주 권장되는 패턴은 아..
spread operator (배열의 복사와 활용) -> 펼침 연산자spread 구문을 사용할 경우 배열이나 문자열과 같이 반복가능한 문자를 0개 이상의 인수(함수로 호출할 경우) 또는 요소(배열 리터럴의 경우) 로 확장하여, 0개 이상의 key-value 의 쌍으로 객체를 확장할수 있다. 12345// spread operator let pre = ["apple", "orange", 100];let newData = [...pre];console.log(pre, newData);cs>["apple", "orange", 100]["apple", "orange", 100] 같은 내용이 출력되지만 참조가 같은 것은 아니다. 12345// spread operator let pre = ["apple", "or..
String 에 새로운 메서드(Method) 1234let str = "hello world ! ^^ ~~";let matchstr = "hello";console.log(str.startWith(matchstr)); Colored by Color Scriptercs startWith : 값을 잘라 대조하는 역할 cf) endWith 123let str = "hello world ! ^^ ~~";let matchstr = "hello";console.log(str.includes(matchstr));cs> true -> 해당 값이 포함되었는지 확인 for of (순회하기)iterator 와 비슷한 역할 1234var data =[1, 2, undefined, NaN, null, ""];data.forEa..
const선언된 변수 지키기 (한번 선언된 변수에 재할당할 수 없는 상수) 1234567function home() { const homename ='my house'; homename = "your house"; console.log(homename);} home();cs error 발생"TypeError: Assignment to constant variable. at home (nucusoneye.js:3:12) at nucusoneye.js:7:1 at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924 at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866" => 해당 error ..
최근댓글