pragma solidity >= 0.7.0 < 0.9.0;
contract test1234{
mapping(uint256=>uint256) ageList;
function setAgeList(uint256 _index,uint256 _age) public {
ageList[_index] = _age;
}
function getAgeList(uint256 _index) public view returns(uint256){
return ageList[_index];
}
}
js 사용하던 map 배열 함수와는 사용 방법이 다르다.
mapping(1:uint256=>2:uint256) ageList;
1:uint256:key
2:uint256:value
ageList 변수명을 만들고 key ,value Type 을 지정 해준다
ageList[_index] = _age 배열 안에[1 설정해준 키값을 입력]
2 _age = value 맞는 2번 타입을 입력
ageList[_index] = [입력한 키값을 입력] 입력하면 위에서 입력한 key,value 불러와 진다.