function showName(name){
console.log(arguments.lengt)
console.log(arguments[0])
console.log(arguments[1])
}
showName('Mike', 'Tom')
//2
//'Mike'
//'Tom'
function User(name, age, ...skills){
this.name = name
this.age = age
this.skills = skills
}
const user1 = new User('mike', 30, 'js', 'html', 'node')
const user2 = new User('tom', 20, 'english', 'javascript')
const user3 = new User('anna', 10, 'css')
console.log('user1: ', user1);
console.log('user2: ', user2);
console.log('user3: ', user3);
let arr = [1, 2, 3]
let arr2 = [...arr]
console.log('arr2: ', arr2);
let user = {name: 'mike', age: 30}
let user2 = {...user}
user2.name = 'Tom'
console.log(user2); //user2: { name: 'Tom', age: 30 }
[배열 사용 시]
//concat
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [7,8,9]
const arrWrap = arr1.concat(arr2, arr3)
// arr1을 [4,5,6,1,2,3] 으로 만들기
arr2.reverse().forEach((num) => { arr.unshift(num) })
▼
arr1 = [...arr2, ...arr1]
[객체에서 사용]
let user = {name: 'bini'}
let info = {age: 30}
let fe = ['js', 'react']
let lang = ['english', 'korean']
user = Object.assign({}, user, info, {
skills: [],
})
fe.forEach((item)=>{user.skills.push(item)})
lang.forEach((item)=>{user.skills.push(item)})
user = {
...user,
...info,
skills: [...fe, ...lang]
}
console.log('user: ', user);