Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:38:10+00:00 2026-06-11T16:38:10+00:00

If I want to count the items in the map structure, what statement should

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:38:11+00:00Added an answer on June 11, 2026 at 4:38 pm

    Use len(m). From http://golang.org/ref/spec#Length_and_capacity

    len(s)    string type      string length in bytes
              [n]T, *[n]T      array length (== n)
              []T              slice length
              map[K]T          map length (number of defined keys)
              chan T           number of elements queued in channel buffer
    

    Here are a couple examples ported from the now-retired SO documentation:

    m := map[string]int{}
    len(m) // 0
    
    m["foo"] = 1
    len(m) // 1
    

    If a variable points to a nil map, then len returns 0.

    var m map[string]int
    len(m) // 0
    

    Excerpted from Maps – Counting map elements. The original author was Simone Carletti. Attribution details can be found on the contributor page. The source is licenced under CC BY-SA 3.0 and may be found in the Documentation archive. Reference topic ID: 732 and example ID: 2528.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ORMLite, I want to count the number of database items that fit certain
We want to count number of shakes done by user. We tried motionBegan, motionEnded
I need an if/else statement for my CSS which can count list items. Would
I have 3 tables setup (items, reviews, ratings). I want to count the total
I want to count the number of items in a NSArray and perform some
I want to count the div that has a class name items and has
I want to return the count of items in this domain. I know count
I want to count how many g items appear in a list, below is
I want to count the total items that belong to a group of parent
I'm using a DataPager control, I want to change count items on each page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.