Remove the first 3 objects in an array

Options
liam
liam Member
edited December 2022 in ? Help! I'm a Noob

I have 10 objects in an array and i want to remove the first 3 object in the array without any condition.

How do i do this ? i've search the docs and forum but could not find the solution.

Tagged:

Answers

  • dorilama
    dorilama Member
    Options

    Have you tried with a "range" filter?

    The documentation is here: https://docs.xano.com/working-with-data/data-type-filters/array-filter

    In your case it would be start 4 and end 10.

    Let me know how it goes

    Mariano

  • liam
    liam Member
    edited December 2022
    Options

    @dorilama hmmm this requires us to know the length of the array first right ?

    what if i don't know the array length ?

    it can be 10 objects or 5 objects or 100 objects in array. We need to remove the first three element from that array

  • dorilama
    dorilama Member
    Options

    the filter "count" returns the number of items in an array

  • liam
    liam Member
    Options

    @dorilama this is how my array looks like this

    {"instagram_feeds":[

    {"id":"2885669349228547921","type":"GraphVideo","likes":200,}

    {"id":"18271872364637463744","type":"GraphVideo","likes":7361,}

    {"id":"918291829172918218223","type":"GraphVideo","likes":71161,}

    {"id":"62520471524457291283","type":"GraphVideo","likes":261,}

    {"id":"012891278172817212333","type":"GraphVideo","likes":161,}

    {"id":"09871625182447823783","type":"GraphVideo","likes":741,}

    ]}

    we want to remove the first three objects, is this still possible with range ?

  • dorilama
    dorilama Member
    Options

    Yes, it is possible.

    I'm from my phone now but you can read in the docs:

    Returns array of values between the specified start/stop.

    If you don't know the length in advance tou can use the filter "count" to get it.

    Give it a try and let me know how it goes.

  • Sahira_Mehta
    Options

    Hi @ilam It would be great if you can elaborate the use case as well,

    According to the above comments I would say :

    Get the total number(Count) of object in an array(check if there is any object or not), if there is any object available -> compare the count of object with 3 -> if <=3 delete all else delete first three using 'Range' Function(Specified range will start from 4 and end at 10) like @Dorian A elaborated above.

    Give it a try, it should work.

  • dorilama
    dorilama Member
    Options

    @Sahira_Mehta "range" will not delete the items from the array, it will select and return the items in the range

  • Sahira_Mehta
    Options

    @dorilama oh mybad, I mistyped it, lol!

    I meant use "Range" to select the items from the array and then remove the first 3 items

    Thank you letting me know @dorilama and Happy new year buddy! :)