[swift] 30.foreach문에서 인덱스 같이 가져오기(enumerated)

RudinP·2023년 9월 23일
0

Study

목록 보기
48/227

for (index, 아이템이름) in 배열이름.enumerated(){
code
}

let myFriendsArray : [String] = ["a", "b", "c", "d"]

var friendsWithIndex : [String] = []

//index없는 Foreach
myFriendsArray.Foreach{ aFriend in 
	print(aFriend)
}

for (index, aFriend) in myFriendsArray.enumerated(){
	print("index: \(index), item: \(aFriend)")
    friendsWithIndex.append("\(index).번 \(aFriend)")
}
profile
곰을 좋아합니다. <a href = "https://github.com/RudinP">github</a>

0개의 댓글