Created
July 26, 2023 09:52
-
-
Save zlrlo/3a37762b48b0f2157379bc77c9184e4c to your computer and use it in GitHub Desktop.
[JS] slice 얕은 복사
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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