If I want to count the items in the map structure, what statement should I use?
I tried to use
for _, _ := range m {...}
but it seems the syntax is false.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
len(m). From http://golang.org/ref/spec#Length_and_capacityHere are a couple examples ported from the now-retired SO documentation:
If a variable points to a
nilmap, thenlenreturns 0.