# Get varRefs of whole container

**URL:** <https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [February 19, 2026, 11:05am UTC](https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726 "2026-02-19T11:05:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [February 19, 2026, 11:05am UTC](https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726/1 "2026-02-19T11:05:02Z")

</div>

Is there a way to get the variable refs of the whole container?

```julia
julia> @variable(model, u[1:2])
2-element Vector{VariableRef}:
 u[1]
 u[2]

julia> variable_by_name(model, "u[2]")
u[2]

```

How do I get all `u` as `Vector{VariableRef}`?

---

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [February 19, 2026, 11:39am UTC](https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726/2 "2026-02-19T11:39:52Z")

</div>

If you mean a method by a string, I assume that doesn’t exist. Just use `u`?  
Why do you want this?

---

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [February 19, 2026, 11:43am UTC](https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726/3 "2026-02-19T11:43:33Z")

</div>

No just `"u"` does not work, it tried that first.

---

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [February 19, 2026, 11:54am UTC](https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726/4 "2026-02-19T11:54:34Z")

</div>

I didn’t mean `"u"`, I meant `u` the reference.

And actually you can call `u` out directly via `model[:u]` or `model[Symbol("u")]`.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 19, 2026, 7:44pm UTC](https://discourse.julialang.org/t/get-varrefs-of-whole-container/135726/5 "2026-02-19T19:44:16Z")

</div>

Dropping this link to the documentation for posterity:

> **[String names, symbolic names, and bindings - Variables · JuMP](https://jump.dev/JuMP.jl/stable/manual/variables/#variable_names_and_bindings)**
>
> The term variable in mathematical optimization has many meanings. For example, optimization variables (also called decision variables) are the unknowns $x$ that we are solving for in the problem: | Documentation for JuMP.

JuMP uses a single flat namespace for string names. In general, if you want to be able to access a structured view of your model components, you should maintain a data structure yourself. The `model[:key]` approach is a helpful utility, but it doesn’t work for every case (for example, anonymous variables and constraints).
