Skip to content
Node: Object.keys(obj)github.com/sahilkhaire/gox/maputil

Keys

Overview ​

Keys returns map keys (Object.keys).

If you are coming from Node.js, the closest pattern is Object.keys(obj).

Signature ​

go
func Keys[K comparable, V any](m map[K]V) []K

Compare: Node.js · Standard Go · gox ​

js
Object.keys(obj)
go
keys := make([]string, 0, len(m))
for k := range m { keys = append(keys, k) }
go
import "github.com/sahilkhaire/gox/maputil"

maputil.Keys(obj)

Example ​

go
import "github.com/sahilkhaire/gox/maputil"

maputil.Keys(obj)

Tips ​

Import github.com/sahilkhaire/gox/maputil and call Keys directly. See the comparison below for the standard library equivalent.

Standard library alternative ​

Use the standard library directly:

go
keys := make([]string, 0, len(m))
for k := range m { keys = append(keys, k) }

← Back to maputil package overview

MIT Licensed · Built for Node.js developers moving to Go