본문 바로가기

프론트엔드 공부/javscript

(34)
객체불러오기(펼침연산자사용>복사,추가,결합) { //객체불러오기(펼침연산자,복사) const ob18 = { a: 100, b: 200, c: "javascript" } const spread = { ...ob18 }; document.write(spread.a, " "); document.write(spread.b, " "); document.write(spread.c, " "); document.write( " "); } { //객체불러오기(펼침연산자,추가) const ob19 = { a: 100, b: 200, c: "javascript" }; const spread = { ...ob19, d: "react" }; document.write(spread.a, " "); document.write(spread.b, " "); document.w..
객체불러오기(변수,forin,map) //객체불러오기(변수로 불러오기) //이렇게 쓰는 경우가 많다 { const ob15 = { a: 100, b: 200, c: "javascript" } const name1 = ob15.a; const name2 = ob15.b; const name3 = ob15.c; document.write("*** 50. 객체 불러오기*** "); document.write(name1, " "); document.write(name2, " "); document.write(name3, " "); } //객체 불러오기(for in) //view에서는 이걸 많이쓰고react에서는 map 많이씀 { const ob16 = { a: 100, b: 200, c: "javascript" } document.write("**..
객체구조분해할당 //객체구조분해할당1 { const ob1 ={ a:100, b:200, c:300 } const{a,b,c} = ob1; document.write(a+b ," ");//300 } //객체구조분해할당2(새 변수 할당) { const ob2 ={ a:100, b:200, c:300 } const{ a:name1, b:name2, c:name3 } = ob2; document.write(name1+name3," "); //400 } //선언없는 객체구조분해할당 { const { a=100, b=200, c=300 } = {b:500,c:600} document.write(b+c);//1100 }
객체선언,객체생성자함수 //객체 선언하기1 { document.write("*** 35. 객체선언(생성자함수-key값x)*** "); const ob1 = new Object(); ob1[0] = 100; ob1[1] = 200; ob1[2] = "javascript"; document.write(ob1[0], " "); document.write(ob1[1], " "); document.write(ob1[2], " "); } //객체 선언하기2 (key, value) { document.write("*** 36. 객체선언(생성자함수-key&value)*** "); const ob2 = new Object(); ob2.a = 100; ob2.b = 200; ob2.c = "javascript"; document.write(ob..
배열메서드 find(), filter() 차이 find(function(){}) => 데이터요소들중 해당 조건의 첫번째 값가져옴 filter(function() =데이터 요소들중 해당조건의 데이터요소들을 배열로 생성 //배열 메서드 find() : 데이터 요소 찾기 { const arr29 = [100, 200, 300, 400, 500]; //const target1 = arr29.find(function(){}); //undefined const target1 = arr29.find((element) => { return element > 100 }); const target2 = arr29.find(el => el == 200); document.write("*** 31. 배열 메서드 find() *** "); document.write(tar..
array.every(function);array.some(function); //every method const numbers = [200,101,450,789]; function isOver100(n){ return n > 100; } console.log(numbers.every(isOver100)); //배열의 모든 값이 조건부에 맞는지 확인할때만 유용함 //some -one element const numbers= [10,50,60,102]; function isBiggerThan100(n){ return n>100; } console.log(numbers.some(isBiggerThan100)); //true
array.includes //array.includes const names =['dom','bob','mary']; console.log(names.includes('dom'));//true 배열이 특정 요소를 포함하고 있는지를 boolean값으로 판별함 문자나 문자열을에서 특정 단어등을 찾을 때는 대소문자 구분. developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
단축평가값(circuite evaluation) const result = 0 || 40 || 60; console.log(result);//40 falsy truthy truthy const result2 = 0 || '' || 60; console.log(result2);//60 논리 연산자들은 왼쪽 > 오른쪽으로 실행됌. 이 연산자들은 결과를 얻게 되면 평가를 중단함. and 연산자에서는 false를 첫번째로, or 연산자에서는 true를 첫번째로 작성하는 것이 유용함