Skip to content

Instantly share code, notes, and snippets.

@zlrlo
Created July 26, 2023 09:52
Show Gist options
  • Select an option

  • Save zlrlo/3a37762b48b0f2157379bc77c9184e4c to your computer and use it in GitHub Desktop.

Select an option

Save zlrlo/3a37762b48b0f2157379bc77c9184e4c to your computer and use it in GitHub Desktop.
[JS] slice 얕은 복사
// Using slice, create newCar from myCar.
let myHonda = { color: 'red', wheels: 4, engine: { cylinders: 4, size: 2.2 } }
let myCar = [myHonda, 2, 'cherry condition', 'purchased 1997']
let newCar = myCar.slice(0, 2)
// Display the values of myCar, newCar, and the color of myHonda
// referenced from both arrays.
console.log('myCar = ' + JSON.stringify(myCar))
console.log('newCar = ' + JSON.stringify(newCar))
console.log('myCar[0].color = ' + myCar[0].color)
console.log('newCar[0].color = ' + newCar[0].color)
// Change the color of myHonda.
myHonda.color = 'purple'
console.log('The new color of my Honda is ' + myHonda.color)
// Display the color of myHonda referenced from both arrays.
console.log('myCar[0].color = ' + myCar[0].color)
console.log('newCar[0].color = ' + newCar[0].color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment