TIL04. JavaScript : About Array

ID์งฑ์žฌยท2021๋…„ 9์›” 1์ผ
0

JavaScript

๋ชฉ๋ก ๋ณด๊ธฐ
16/19
post-thumbnail

๐Ÿ“Œ ์ด ํฌ์ŠคํŒ…์—์„œ๋Š” JavaScript์˜ ๋ฐฐ์—ด์˜ ๊ตฌ์กฐ, new Array ์„ ์–ธ๋ฐฉ์‹๊ณผ ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ์„ ์–ธ ๋ฐฉ์‹์— ๋”ฐ๋ฅธ ์ฐจ์ด์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.



๐ŸŒˆ About Array

๐Ÿ”ฅ Why use arrays?

๐Ÿ”ฅ "new Array declaration" & "literal declaration"

๐Ÿ”ฅ CRUD in Array



1. Why use arrays?


๐Ÿค” ๋ฐฐ์—ด์€ ์™œ ์“ธ๊นŒ?

โœ”๏ธ ๋ฐฐ์—ด(Array)์€ ์˜ํ™”๊ด€ ๊ฐ™์•„์š”. ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๊ณ , ์ด ์—ฌ๋Ÿฌ๊ฐ’์„ ์œ„์น˜(index๊ฐ’)์— ๋”ฐ๋ผ ์ฝ์–ด๋“ค์ด๋Š”๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋งˆ์น˜ ์˜ํ™”๊ด€์— ์ขŒ์„ ๋ฒˆํ˜ธ๊ฐ€๋ฅผ ํ†ตํ•ด ๋ˆ„๊ตฐ๊ฐ€๋ฅผ ๊ฐ€๋ฅดํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๊ณผ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค.
โœ”๏ธ ๋ฐฐ์—ด ๋‚ด์—๋Š” ๋ฌธ์ž, ์ˆซ์ž, ๋ฐฐ์—ด, ํ•จ์ˆ˜ ๋“ฑ ๋‹ค์–‘ํ•œ Data Type์„ ํ•จ๊ป˜ ๋‹ด์„ ์ˆ˜ ์žˆ๊ณ , ๋ฐฐ์—ด ๋‚ด์— ๋‹ด๊ธด Data๋ฅผ ์š”์†Œ ๋˜๋Š” ์›์†Œ๋ผ ๋ถ€๋ฆ…๋‹ˆ๋‹ค.
โœ”๏ธ ํŠนํžˆ, ๋ฐฐ์—ด ๋‚ด ์›์†Œ๋“ค์„ Create, Read, Update, Delete ํ•˜๋Š”๋ฐ ์œ ์šฉํ•œ ๋งค์„œ๋“œ๋“ค์ด ๋‹ค์–‘ํ•˜๊ฒŒ ์ œ๊ณต๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

let myArray = [19, 44, 'good', false]
console.log(myArray)
let first = myArray[0] // ์ฒซ๋ฒˆ์งธ(0๋ฒˆ) ์š”์†Œ
let second = myArray[1] // ๋‘๋ฒˆ์งธ(1๋ฒˆ) ์š”์†Œ
let third = myArray[2] // ์„ธ๋ฒˆ์งธ(2๋ฒˆ) ์š”์†Œ
let fourth = myArray[3] // ๋„ค๋ฒˆ์งธ(3๋ฒˆ) ์š”์†Œ
console.log(first) // 19
console.log(second) // 44
console.log(third) // 'good'
console.log(fourth) // false
console.log(myArray.length) // 4
myArray[0] = 500
console.log(myArray) // [ 500, 44, 'good', false ]
myArray[3] = true
console.log(myArray) // [ 500, 44, 'good', true ]

๐Ÿค” ๋ฐฐ์—ด์˜ ๊ธธ์ด์—์„œ 1์„ ๋นผ ๊ฐ’๊ณผ ๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index๊ฐ’๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

let myArray1 = [1]
console.log(`๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index ๊ฐ’ : ${myArray1.indexOf(1)}`) // ๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index ๊ฐ’ : 0
console.log(`myArray ์›์†Œ์˜ ๊ฐฏ์ˆ˜ -1 ๊ฐ’ :  ${myArray1.length - 1}`) // myArray ์›์†Œ์˜ ๊ฐฏ์ˆ˜ -1 ๊ฐ’ :  0
console.log(myArray1.indexOf(1) === myArray1.length - 1) // true
//
let myArray2 = [1,2,3,4,5,6,7,8,9,10]
console.log(`๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index ๊ฐ’ : ${myArray2.indexOf(10)}`) // ๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index ๊ฐ’ : 9
console.log(`myArray ์›์†Œ์˜ ๊ฐฏ์ˆ˜ -1 ๊ฐ’ :  ${myArray2.length - 1}`) // myArray ์›์†Œ์˜ ๊ฐฏ์ˆ˜ -1 ๊ฐ’ :  9
console.log(myArray2.indexOf(10) === myArray2.length - 1) // true
//
let myArray3 = [100, 200, 300, 400, 500, 1000, 2000, 3000, 4000, 'Hello', 'last']
console.log(`๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index ๊ฐ’ : ${myArray3.indexOf('last')}`) // ๋งˆ์ง€๋ง‰ ์›์†Œ์˜ index ๊ฐ’ : 10
console.log(`myArray ์›์†Œ์˜ ๊ฐฏ์ˆ˜ -1 ๊ฐ’ :  ${myArray3.length - 1}`) // myArray ์›์†Œ์˜ ๊ฐฏ์ˆ˜ -1 ๊ฐ’ :  10
console.log(myArray3.indexOf('last') === myArray3.length - 1) // true

๐Ÿค” ๋‹ค์ฐจ์› ๋ฐฐ์—ด์˜ ์›์†Œ๊ฐ’์—๋Š” ์–ด๋–ป๊ฒŒ ์ ‘๊ทผํ• ๊นŒ?

๋‹ค์ฐจ์› ๋ฐฐ์—ด์€ ์ค‘์ฒฉ ๋ฐฐ์—ด์ด๋ผ๊ณ ๋„ ๋ถˆ๋ฆฌ๋ฉฐ, ๋ฐฐ์—ด ๋‚ด์— ๋˜ ๋‹ค๋ฅธ ๋ฐฐ์—ด์ด ๊นŠ์ด๋ฅผ ์ด๋ฃจ๋ฉฐ ์กด์žฌํ•˜๋Š” ํ˜•ํƒœ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

let nestedArray = [1, ['Jaewon', 'Seoul', 'Male', [true, false]], ['๐Ÿ•', '๐Ÿ”', '๐Ÿฆ'], 'JavaScript']
console.log(nestedArray[0]) // 1
console.log(nestedArray[1]) // [ 'Jaewon', 'Seoul', 'Male', [ true, false ] ]
console.log(nestedArray[1][0]) // 'Jaewon'
console.log(nestedArray[1][1]) // 'Seoul'
console.log(nestedArray[1][2]) // 'Male'
console.log(nestedArray[1][3]) // [ true, false ]
console.log(nestedArray[1][3][0]) // true
console.log(nestedArray[1][3][1]) // false
console.log(nestedArray[2]) // [ '๐Ÿ•', '๐Ÿ”', '๐Ÿฆ' ]
console.log(nestedArray[3]) // JavaScript


2. "new Array declaration" & "literal declaration"


๐Ÿค” ๋ฐฐ์—ด์˜ 2๊ฐ€์ง€ ์„ ์–ธ ๋ฐฉ์‹

โœ”๏ธ ๋ฐฐ์—ด์€ "new Array ์„ ์–ธ"๊ณผ "๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์„ ์ด์šฉํ•œ ์„ ์–ธ" ์ด ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

1) "new Array ์„ ์–ธ"

let myArray = new Array()
console.log(myArray) // []

2) "๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์„ ์ด์šฉํ•œ ์„ ์–ธ"

let myArray = []
console.log(myArray) // []

๐Ÿค” "new Array ์„ ์–ธ" ๋ฐฉ์‹์€ ์ •์ˆ˜ ํ•˜๋‚˜๋งŒ ์›์†Œ๋กœ ๊ฐ€์ง„ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

"new Array ์„ ์–ธ"์€ ํ•˜๋‚˜์˜ ์ˆซ์ž๋งŒ ๋„ฃ์œผ๋ฉด ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋กœ ์ธ์‹ํ•˜๊ณ , ์—ฌ๋Ÿฌ๊ฐœ ์ˆซ์ž๋ฅผ ์ „๋‹ฌํ•˜๋ฉด ๋ฐฐ์—ด์˜ ์›์†Œ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์ด์œ ๋กœ "new Array ์„ ์–ธ"๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ •์ˆ˜ ํ•˜๋‚˜๋งŒ ์›์†Œ๋กœ ๊ฐ€์ง„ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

let myArray = new Array(5)
console.log(myArray) // [ <5 empty items> ]
console.log(myArray[0]) // undefined
console.log(myArray[1]) // undefined
console.log(myArray[2]) // undefined
console.log(myArray[3]) // undefined
console.log(myArray[4]) // undefined

"new Array ์„ ์–ธ"์— ์—ฌ๋Ÿฌ ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋ฉด ์ด๋ฅผ ์›์†Œ๊ฐ’์œผ๋กœ ์ธ์‹ํ•ฉ๋‹ˆ๋‹ค.

let myArray = new Array(5, 4, 3, 2, 1)
console.log(myArray) // [ 5, 4, 3, 2, 1 ]
console.log(myArray[0]) // 5
console.log(myArray[1]) // 4
console.log(myArray[2]) // 3
console.log(myArray[3]) // 2
console.log(myArray[4]) // 1

๐Ÿค” "new Array ์„ ์–ธ" ๋ฐฉ์‹์€ ์ผ๊ด€์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

"new Array ์„ ์–ธ"๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, 1๊ฐœ์˜ ๋ฌธ์ž์—ด์„ ๋„ฃ์œผ๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”? ์ด๋•Œ๋Š” ๋˜ 1๊ฐœ์˜ ๋ฌธ์žํ˜• ์›์†Œ๋งŒ ๊ฐ€์ง„ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

let myArray = new Array("5")
console.log(myArray) // [ '5' ]
console.log(myArray[0]) // 5

๐Ÿค” "new Array ์„ ์–ธ" ๋ฐฉ์‹์€ ์ง๊ด€์„ฑ์ด ๋–จ์–ด์ง‘๋‹ˆ๋‹ค.

์ด๋ฒˆ์—๋Š” toString() ๋งค์„œ๋“œ๋ฅผ ํ†ตํ•ด "new Array ์„ ์–ธ"ํ•œ ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์ณ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ "new Array ์„ ์–ธ" ๋ฐฉ์‹์€ ๋‹ค์†Œ ์ง๊ด€์„ฑ์ด ๋–จ์–ด์ง‘๋‹ˆ๋‹ค.

let myArray1 = new Array(5)
console.log(myArray1.toString()) // ,,,,
let myArray2 = new Array(5, 4, 3, 2, 1)
console.log(myArray2.toString()) // 5,4,3,2,1

๐Ÿค” "๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ์„ ์–ธ" ๋ฐฉ์‹์€ ๋ณด๋‹ค ์ง๊ด€์ ์ด๊ณ  ๊ฐ„๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

์ด์™€๋Š” ๋‹ค๋ฅด๊ฒŒ " ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ์„ ์–ธ"์€ ๋ฐฐ์—ด์˜ ์ƒํƒœ๋ฅผ ์ง๊ด€์ ์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ฐ„๊ฒฐํ•˜๋‹ค๋Š” ์žฅ์ ์œผ๋กœ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

// myArray0
let myArray0 = []
console.log(myArray0) // []
console.log(myArray0[0]) // undefined
console.log(myArray0.toString())
// myArray1
let myArray1 = [5]
console.log(myArray1[0]) // 5
console.log(myArray1.toString()) // "5"
// myArray2
let myArray2 = [5, 4, 3, 2, 1]
console.log(myArray2[0]) // 5
console.log(myArray2[1]) // 4
console.log(myArray2[2]) // 3
console.log(myArray2[3]) // 2
console.log(myArray2[4]) // 1
console.log(myArray2.toString()) // "5,4,3,2,1"


3. CRUD in Array


๐Ÿค” psuh() : push ๋งค์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์— ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

let myArray = [100, 'Python', 7, false]
myArray.push('Hello') 
console.log(myArray) // [ 100, 'Python', 7, false, 'Hello' ]
myArray.push('500', '300')
console.log(myArray) // [ 100, 'Python', 7, false, 'Hello', '500', '300' ]
myArray.push(['Jaewon', 33, 'Seoul', 'Male'])
console.log(myArray) // [100, 'Python', 7, false, 'Hello', '500', '300', [ 'Jaewon', 33, 'Seoul', 'Male' ]]

๐Ÿค” pop() : pop ๋งค์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ๋ ์š”์†Œ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.

let myArray = [100, 'Python', 7, false]
let getPop = myArray.pop()
console.log(getPop) // false
console.log(myArray) // [ 100, 'Python', 7 ]
//
getPop = myArray.pop()
console.log(getPop) // 7
console.log(myArray) // [ 100, 'Python']
//
getPop = myArray.pop()
console.log(getPop) // 'Python'
console.log(myArray) // [ 100]
//
getPop = myArray.pop()
console.log(getPop) // 100
console.log(myArray) // []

๐Ÿค” unshift() : unshift ๋งค์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์— ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. push๋ณด๋‹ค ๋Š๋ฆฝ๋‹ˆ๋‹ค.

let myArray = [100, 'Python', 7, false]
myArray.unshift('Hello') 
console.log(myArray) // [ 'Hello', 100, 'Python', 7, false ]
myArray.unshift('500', '300')
console.log(myArray) // [ '500', '300', 'Hello', 100, 'Python', 7, false ]
myArray.unshift(['Jaewon', 33, 'Seoul', 'Male'])
console.log(myArray) // [[ 'Jaewon', 33, 'Seoul', 'Male' ], '500', '300', 'Hello', 100, 'Python', 7, false]

๐Ÿค” shift() : shift ๋งค์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ์ฒซ ์š”์†Œ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค. pop๋ณด๋‹ค ๋Š๋ฆฝ๋‹ˆ๋‹ค.

let myArray = [100, 'Python', 7, false]
let getPop = myArray.shift()
console.log(getPop) // 100
console.log(myArray) // [ 'Python', 7, false ]
//
getPop = myArray.shift()
console.log(getPop) // "Python"
console.log(myArray) // [ 7, false ]
//
getPop = myArray.shift()
console.log(getPop) // 7
console.log(myArray) // [ false ]
//
getPop = myArray.shift()
console.log(getPop) // false
console.log(myArray) // []

๐Ÿค” splice() : splice ๋งค์„œ๋“œ๋Š” ๋ฐฐ์—ด ๋‚ด์˜ ํŠน์ •ํ•œ ์š”์†Œ๋ฅผ ์‚ญ์ œํ•˜๊ฑฐ๋‚˜, ๋‹ค๋ฅธ ์š”์†Œ๋กœ ๋Œ€์น˜ํ•˜๊ฑฐ๋‚˜ ์ƒˆ๋กœ์šด ์š”์†Œ๋ฅผ ์‚ฝ์ž…ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

โœ”๏ธ ์ฒซ๋ฒˆ์งธ ์ธ์ž๋Š” ์‹œ์ž‘ ์ง€์ ์„ ์ง€์ •ํ•  ๋•Œ ์“ฐ์ด๊ณ , ๋‘๋ฒˆ์งธ ์ธ์ž๋Š” ์‚ญ์ œํ•  ๊ฐฏ์ˆ˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์„ธ๋ฒˆ์งธ ์ธ์ž๋Š” ์‹œ์ž‘ ์ง€์ ๋ถ€ํ„ฐ ๋Œ€์ฒดํ•  ์š”์†Œ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ํ•„์š”์— ๋”ฐ๋ผ ์ธ์ž๋ฅผ 1๊ฐœ๋งŒ ์“ธ์ˆ˜๋„ ์žˆ์œผ๋‚˜, ์ˆœ์„œ๋ฅผ ์ง€์ผœ์•ผํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด, ์‚ญ์ œํ•˜์ง€ ์•Š๊ณ  ์‚ฝ์ž…๋งŒ ํ•  ๊ฒฝ์šฐ์— ๋‘๋ฒˆ์งธ ์ธ์ž์—๋Š” 0์„ ์‚ฝ์ž…ํ•ด์ค๋‹ˆ๋‹ค. splice ๋งค์„œ๋“œ๋Š” ์›๋ณธ์— ์ง์ ‘ ์˜ํ–ฅ์„ ๋ฏธ์น˜๊ธฐ ๋•Œ๋ฌธ์— ์œ ์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

let spliceArray = [1, 100, 'hi', true, 99, false]
console.log(spliceArray.splice(0, 2, [10, 20])) // [ 1, 100 ]
console.log(spliceArray) // [ [ 10, 20 ], 'hi', true, 99, false ]
console.log(spliceArray.splice(1, 1, 'bye')) // [ 'hi' ]
console.log(spliceArray) // [ [ 10, 20 ], 'bye', true, 99, false ]
console.log(spliceArray.splice(0, 5, 'reset')) // [ [ 10, 20 ], 'bye', true, 99, false ]
console.log(spliceArray) // [ 'reset' ]

๐Ÿค” concat(): concat ํ•จ์ˆ˜๋Š” ๋‘˜ ์ด์ƒ์˜ ๋ฐฐ์—ด์„ ํ•ฉ์ณ์ค๋‹ˆ๋‹ค.

let myArray1 = ['ํ•˜๋‚˜', '๋‘˜', '์…‹']
let myArray2 = ['์…‹', '๋‘˜', 'ํ•˜๋‚˜']
let conatArray = myArray1.concat(myArray2);
console.log(conatArray); // [ 'ํ•˜๋‚˜', '๋‘˜', '์…‹', '์…‹', '๋‘˜', 'ํ•˜๋‚˜' ]

๐Ÿค” slice(start, end) : slices๋Š” ๋ฐฐ์—ด ๋‚ด ์š”์†Œ๋ฅผ ์ถ”์ถœํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

โœ”๏ธ slice ๋งค์„œ๋“œ๋Š” ๋ฐฐ์—ด์„ ์ถ”์ถœํ•˜๊ธฐ ์œ„ํ•ด 2๊ฐœ์˜ ๊ฐ’์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ฒซ๋ฒˆ์งธ๋Š” start index์ด๊ณ , ๋‘๋ฒˆ์งธ๋Š” end index์ž…๋‹ˆ๋‹ค. start index์˜ ๊ฐ’์€ ํฌํ•จ๋˜๊ณ , end index์˜ ๊ฐ’ ์ด์ „๊นŒ์ง€ ์ถ”์ถœํ•ด์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ end index๋ฅผ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์œผ๋ฉด, start index๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์›์†Œ๊นŒ์ง€ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ slice ๋งค์„œ๋“œ๋Š” ์›๋ณธ ๋ฐฐ์—ด์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ฆ‰, ๋ฐฐ์—ด์˜ ์›์†Œ๋ฅผ ์ถ”์ถœํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

let sliceArray = [1, 100, 'hi', true, 99, false]
console.log(sliceArray.slice(0)) // [ 1, 100, 'hi', true, 99, false ]
console.log(sliceArray.slice(0,-1)) // [ 1, 100, 'hi', true, 99 ]
console.log(sliceArray.slice(3,5)) // [ true, 99 ]
console.log(sliceArray.slice(1, 4)) // [ 100, 'hi', true ]
console.log(sliceArray.slice(-1)) // [ false ]
console.log(sliceArray) // [ 1, 100, 'hi', true, 99, false ]
profile
Keep Going, Keep Coding!

0๊ฐœ์˜ ๋Œ“๊ธ€