当前位置:网站首页>JS written test question: array

JS written test question: array

2022-06-21 14:27:00 Advanced mathematics volume II half price

const fruit = [1, 2, 3]
 
fruit.slice(0, 1)
console.log(fruit) // [1,2,3]

fruit.splice(0, 1)
console.log(fruit) // [2,3]
        
fruit.unshift(4)
console.log(fruit) // [4,2,3]

// slice  It doesn't change the original array 

 

 

 

 

 

const user = {
 email: "[email protected]",
 password: "12345"
}
 
const updateUser = ({ email, password }) => {
 if (email) {
  Object.assign(user, { email })
 }
 
 if (password) {
  user.password = password
 }
 
 return user
}
 
const updatedUser = updateUser({ email: "[email protected]" })
 
console.log(updatedUser === user)

//  answer : true  Always in the same space in the operation heap 

原网站

版权声明
本文为[Advanced mathematics volume II half price]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221424598708.html