λ°°μ—΄

0

javascript

λͺ©λ‘ 보기
6/34
post-thumbnail
post-custom-banner

πŸ“ λ°°μ—΄

μˆœμ„œκ°€ μžˆλŠ” κ°’

πŸ“ μš”μ†Œ

element = κ°’

πŸ“ μˆœμ„œ

index // 1이 μ•„λ‹Œ 0 λΆ€ν„° 번호λ₯Ό 맀김

배열을 가지고 놀아 보자

let myNumber = [73,93,86,61,96];
--- myNumber의 인덱슀 3은 61이닀. // myNumber[3]  -> 61
let mynumber = [[1,2],[3,4],[5,6]];  //이쀑배열
--- 1번째 인덱슀 값은 [3,4] -> myNumber[1]
---1번째의 0번째 인덱슀 값은 3 ->mynumber[1][0]

πŸ“Œ λ°°μ—΄μ˜ κ°’ λ³€κ²½ ν•΄λ³΄μž

let myNumber = [73,98,86,61,96];
myNumber[3] = 200;  //인덱슀3 자리 값을 200으둜 λ³€κ²½ 
myNumber = [73,98,86,200,96]

πŸ“Œ λ°°μ—΄μ˜ 길이λ₯Ό 좜λ ₯ ν•˜μž

let myNumber = [73,98,86,61]
Mynumber.length ;  //4

πŸ“Œ λ°°μ—΄ λ’€μͺ½κ³Ό μ•žμͺ½μ— μš”μ†Œ μΆ”κ°€ ν•΄λ³΄μž

Let myNumber = [73,98,86,61];
Mynumber.push(96);  -> myNumber = [73,98,86,61,96] //맨뒀에 96 μΆ”κ°€
Mynumber.unshift(100) ->myNumber = [100,73,98,86,61,96]  //맨 μ•žμͺ½μ— 100 μΆ”κ°€ 

πŸ“Œ λ°°μ—΄μ˜ λ’€μͺ½κ³Ό μ•žμͺ½μ— μš”μ†Œ μ‚­μ œ ν•΄λ³΄μž

let myNumber = [73,98,86,61]
myNumber.pop(); //λ°°μ—΄μ˜ λ§ˆμ§€λ§‰ κ°’ μ‚­μ œ  ->myNumber = [73,98,86]
myNumber.shift() //첫번째 값이 λΉ μ Έ λ‚˜μ˜¨λ‹€ 배열에선 μ‚­μ œ -> myNumber =[ 98,86,61]  λ§¨μ•žκ°’μ΄ μ‚­μ œ

πŸ“Œ νƒ€μž…μ΄ 배열인지 확인 ν•˜κΈ°

Array.isArray(β€˜λ¬Έμžμ—΄β€™) //β€˜false’
Array.isArray(123) //β€˜false’
Array.isArray([1,2,3]) //β€˜true’
Array.isArray([ ])//β€˜true’

πŸ“Œ λ² μ—΄μ˜ 반볡문

  • λ°°μ—΄ μš”μ†Œ 좜λ ₯ν•˜κΈ°
let myNum = [73,98,86,61];
for(let n =0; n < myNum.length; n++){
	myNum[n];
}
  • λ°°μ—΄ν•©κ³„μΆœλ ₯ν•˜κΈ°
myNum=[10,20,40,10];
let sum =0;
for(let n =0; n < myNum.length; n++){
	sum = sum + myNum[n];
}

πŸ“Œ λ°°μ—΄μ—μ„œ νŠΉμ • 값이 μžˆλŠ”μ§€ ν™•μΈν•˜κΈ°

let word = [β€˜ν”Όβ€™, β€˜λ•€β€™,β€™λˆˆλ¬Όβ€™];
Word.indexOf(β€˜ν”Όβ€™)  //0 λ°°μ—΄μ˜κ°’μ΄ 있으면 인덱슀λ₯Ό 좜λ ₯ (λŒ€μ†Œλ¬Έμž ꡬ뢄 μž˜ν•΄μ€˜μ•Όν•¨)
Word.indexOf(β€˜λ•€β€™)  //1 
Word.indexOf(β€˜μ†β€™) // -1 λ°°μ—΄μ˜ 값이 μ—†λŠ”κ±° 검색 ν•˜λ©΄ -1 좜λ ₯  
Word.indexOf(β€˜μ†β€™) !== -1 //배열에 찾고자 ν•˜λŠ” 값이 μžˆλŠ”μ§€ μ—†λŠ”μ§€ μ‚¬μš©ν•˜λŠ” 이프문 

profile
πŸ‘©πŸ»β€πŸ’»ν•­μƒλ°œμ „ν•˜μž πŸ”₯
post-custom-banner

0개의 λŒ“κΈ€