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) []KCompare: 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) }