FAQ
Hi,

Say that I have an array with elements {a,b,c,d,e,f,g,h}. I want to create
a slice containing only elements with, say, index 0, 1, 3 and 6. The
resulting slice would be {a,b,d,g}. Is there a good way to achieve this? I
tried array[0,1,3,6] to no avail...

Jens

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Alexander Kapshuk at Feb 4, 2016 at 4:52 pm

    On Thu, Feb 4, 2016 at 11:45 AM, wrote:
    Hi,

    Say that I have an array with elements {a,b,c,d,e,f,g,h}. I want to create a
    slice containing only elements with, say, index 0, 1, 3 and 6. The
    resulting slice would be {a,b,d,g}. Is there a good way to achieve this? I
    tried array[0,1,3,6] to no avail...

    Jens

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    http://play.golang.org/p/XrktmqVKlO

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • David Bailey at Feb 4, 2016 at 5:22 pm
    If you want the slice to reflect any changes in the array you could do
    this. http://play.golang.org/p/iaHwtZ0eH7
    On Thursday, February 4, 2016 at 8:11:36 AM UTC-8, ehler...@gmail.com wrote:

    Hi,

    Say that I have an array with elements {a,b,c,d,e,f,g,h}. I want to create
    a slice containing only elements with, say, index 0, 1, 3 and 6. The
    resulting slice would be {a,b,d,g}. Is there a good way to achieve this? I
    tried array[0,1,3,6] to no avail...

    Jens
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 4, '16 at 4:11p
activeFeb 4, '16 at 5:22p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase