cosnt object {
name: jotang,
age: 31,
city: busan
phone: 0101234567
};
Object.keys(object) // ['name', 'age', 'city', 'phone']
Object.values(object) // ['jotang', 31, 'busan', 0101234567]
Object.entries(object)
// [['name', 'jotang'], ['age', 31], ['city', 'busan'], ['phone', 0101234567]]
// array에서의 for-in
const name = ['jotang', 'dongtak', 'dama', 'health']
for (let i in name) {
console.log(i) //index value
console.log(name[i]) // 'jotang', 'dongtak' 등 각 요소 반환
}
// object에서의 for-in
cosnt object {
name: jotang,
age: 31,
city: busan
phone: 0101234567
};
for (let i in object) {
console.log(i) // 해당 object의 key // 'name', 'age', 'city', 'phone'
console.log(object[i]) //object의 value // 'jotang',31,'busan',0101234567
}
const array = [1, 2, 3, 4, 5];
array[0] = 1;
array[1] = 2;
//객체 배열
const objects = [{name: '멍멍이'}, {name: '야옹이'}]
object[0] = {name: '멍멍이'}
object[1] = {name: '야옹이'}
const superheroes = ['아이언맨', '토르', '헐크', '스파이더맨']
//for문 사용
for(let i = 0; i < superheroes.length; i++) {
console.log(superheroes[i);
}
// forEach()
superheroes.forEach(hero => {
console.log(hero);
});
map()
const array = [1, 2, 3, 4, 5, 6, 7, 8];
// 위 array를 제곱하여 새로운 array를 만들고 싶다면??
// for 문
const array2 = [];
for(let i = 0; i < array.length; i++) {
array2.push(array[i] * array[i]);
}
const array2 = [];
//forEach()
array.forEach(n => {
array2.push(n * n);
}
//map()
const array2 = n => n * n
const array3 = array.map(array2)
indexOf()
const superheroes = ['아이언맨', '토르', '헐크', '스파이더맨'];
const index = superheroes.indexOf('헐크');
console.log(index) // 2
findIndex() / find()
const todos = [
{
id: 1,
text: '자바스크립트 입문',
done: true
},
{
id: 2,
text: '함수 배우기',
done: true
},
{
id: 3,
text: '객체와 배열 배우기',
done: true
}];
const index = todos.findIndex(todo => todo.id === 2);
console.log(index) // 1
const index2 = todos.find(todo => todo.id === 1);
console.log(index2) // {id: 1, text: '자바스크립트 입문', done: true}
splice() / slice()
splice()
const numbers = [10, 20, 30, 40];
const index = numbers.indexOf(30);
numbers.splice(index, 1);
console.log(numbers); // [10, 20, 40]
// splice(제거할 index, 몇개를 지울지를 의미, 그 자리에 추가될 요소)
slice()
const numbers = [10, 20, 30, 40];
const sliced = numbers.slice(0, 2); // 0부터 시작해서 2전까지
console.log(sliced); // [10, 20]
console.log(numbers); // [10, 20, 30, 40]
// slice(어디서부터 자를지, 어디까지 자를지)
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const concated = arr1.concat(arr2);
console.log(concated); // [1, 2, 3, 4, 5, 6];
// arr1과 arr2에는 변화를 주지 않는다.
const array = [1, 2, 3, 4, 5];
console.log(array.join()); // 1,2,3,4,5
console.log(array.join(' ')); // 1 2 3 4 5
console.log(array.join(', ')); // 1, 2, 3, 4, 5
const numbers = [1, 2, 3, 4, 5];
let sum = array.reduce((accumulator, current) => accumulator + current, 0);
console.log(sum);
https://learnjs.vlpt.us/basics/09-array-functions.html
http://blog.302chanwoo.com/2017/08/javascript-array-method/
1. Problems & Solution 1. problems 1. hero의 left value 의 type이 string. number로 변화하여 계산. 2. image sprite 2. solution 1. parsInt를 사용하여 string에서 number로 변화하여 사용하였다 * parseInt() 함수는 string의 구...
1. Git 1. git clone * 말 그대로 원격 저장소를 복제 한다는 뜻 * $ git clone repository directory : git의 소스코드를 지역저장소로 가져오는 것 * repository :원격 저장소의 URL * directory : 복제대상의 폴더명 * 따라서 특정 repository를 각자 자신의 local ...
1. Object * object 역시 array 처럼 순회가 가능하다. 단지 array와 다르게 명확하게 정해진 순서가 없기 때문에 어떤 순서에 따라 object의 key에 접근하게 될 지는 알 수 없다. ('순서가 보장되지 않은 순회') 1.1 Object.keys() * 개체의 고유 속성의 이름을 array로 반환한다. * reduc...
1. login page - event 1.1 login page event GOAL * ID, PW에 각 한 글자 이상 시 버튼 활성화.(연한파랑 - 파랑) 2.2 problems * event 객체 * 순서 * comInput.value = ''; * key code * event target * callback function * ...
1.instargram Login page - clone - Problems 1. height 설정에 관한 문제 * px, %, vh 2. font(단위/글씨체) * px, em, rem - solution * CSS의 길이 단위 * font-relative length(상대 길이) * 크기가 고정되지 않고 기준에 따라서 유동적으로 ...