배열을 생성할 때 사용하는 리스트 형태의 고수준 객체
const arrayNumbers = [1,2,3,4]
arrayNumbers[0]
arrayNumbers[-1] // 불가능
arrayNumbers.length // 4
arrayNumbers.reverse()
console.log(arrayNumbers) // [4,3,2,1]
arrayNumbers.push('a')
console.log(arrayNumbers) // [4,3,2,1,'a']
arrayNumbers.pop() //'a'
console.log(arrayNumbers) // [4,3,2,1]
arrayNumbers.unshift('a')
console.log(arrayNumbers) // ['a',4,3,2,1]
arrayNumbers.shift() // 'a'
console.log(arrayNumbers) // [4,3,2,1]
arrayNumbers.include(1) //true
arrayNumbers.include(100) // false
-1
을 반환arrayNumbers.indexOf(2) // 2
arrayNumbers.indexOf(100) // -1
,
)를 기준으로 이어준다.arrayNumbers.join() // 4,3,2,1
arrayNumbers.join('') // 4321
arrayNumbers.join('-') //4-3-2-1
객체. key: value 로 구성된 자바스크립트 자료형 중 하나
key는 문자열 타입이고 value는 모든 타입이 가능!
const person = {
name:'sj',
'phone number' : '010111111111',
samsungProducts : {
galaxyTab : 'galaxyTab S7',
galaxyS20 : 'galaxy S20'
}
}
person.name // sj
person['name'] // sj
person['phone number'] // sj
person.samsungProducts.galaxyTab //galaxyTab S7
// person.get() // 불가능..이건 파이썬 문법
const books = ['Eloquent JS', 'JS Ninja']
const comics ={
DC: ['Aquaman','Batman'],
Marvel:['Avengers','Captain Marvel']
}
const bookShop = {
books, //books : books
comics //comics : comics
}
const baby = {
name:'kobe',
cook: function() {
console.log('Hi, I cook!')
}
}
baby.cook() // Hi, I cook!
const baby = {
name:'kobe',
cook() {
console.log('Hi, I cook!')
}
}
baby.cook() // Hi, I cook!
const userInformation = {
name:'sj',
userId:'s1234',
phoneNumber:'010-1111-1111',
email:'sj@naver.com'
}
// -ES5까지 사용하던 방법
const name = userInformation.name
const userId = userInformation.userId
// -ES6+
const {name} = userInformation
const {name,userId,email} = userInformation