Looped Array Element Deletion

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Looped Array Element Deletion

    I want to loop through a structure of arrays using CFScript to delete an
    element in the same position of each array.

    Here is a snipet of code I use to set up the arrays:
    <CFSCRIPT>
    field_list =
    "campaign,header_row,search,delivery_type,mail_typ e,ftp_server,ftp_user,ftp_pass
    ,mailto,mail_subject,ftp_location";

    deliveryStr = STRUCTNEW();
    FOR(idx = 1; idx LTE LISTLEN(field_list); idx = idx + 1)
    {
    field = LISTGETAT(fieldlist,idx);
    "deliveryStr.#field#" = ARRAYNEW(1);
    }
    </CFSCRIPT>

    This code works appropriately.

    Now, say these arrays have 10 elements each and I want to delete the 5th
    element of each because they are a collective set.

    This is what I tried:
    <CFSCRIPT>
    FOR(idx = 1; idx LTE LISTLEN(field_list); idx = idx + 1)
    {
    field = LISTGETAT(fieldlist,idx);
    tmp = ARRAYDELETEAT(EVALUATE("deliveryStr."&field),5);
    }
    </CFSCRIPT>

    It does not error and if I output tmp it equates to 'YES'. But, if I CFDump
    the structure, it has the same number of elements in the arrays as before the
    attempt.

    Any ideas?

    I know I can list each field separately and it will work. I would rather loop
    and save space.

    Thanks.
    Rob

    travelinrob Guest

  2. Similar Questions and Discussions

    1. Array element doesn't keep struct value?
      I'd like each of the following array elements to hold its own structure. <cfset TeamMemberDisplay = arraynew(1)> <cfset querystuct = structnew()>...
    2. Is there a function to see if something is an element of an array?
      ------------------------------------------------ On Tue, 30 Sep 2003 12:58:21 -0400, Dan Anderson <dan@mathjunkies.com> wrote: In general this...
    3. Is there a function to see if something is an element of an array?
      I have a long list of IP addresses I am going to be reading in (using regexps) and then seperating out into a list of IP addresses. I don't want...
    4. Extract Array Element
      HI! I have an array of 15 elements, however I dont want the fifth element. So, how can I extract it from the array so I would have 14 elements? ...
    5. Removing array element by key
      How do i remove an element of an array by its key? I've tried array_s(p)lice to no avail. Either it chops too much or too little with seemingly...
  3. #2

    Default Re: Looped Array Element Deletion

    Hi,

    Try looping around structure and then try to delete from the each array.

    Hope this helps,
    Parvee:light;
    parvee Guest

  4. #3

    Default Re: Looped Array Element Deletion

    Thank you, that does help. Not the looping through the structure, but looking
    at the structure of arrays as an array of arrays. IE.- referencing the arrays
    as structure[array] instead of structure.array. I might be able to get away
    with looping through the structure, but, I cannot be sure that other arrays or
    structures might be added to this structure that will not be of the same length
    or have the same function as these main parts.

    Solution:
    FOR(idx = 1; idx LTE LISTLEN(field_list); idx = idx + 1)
    {
    field = LISTGETAT(field_list,idx);
    tmp = ARRAYDELETEAT(deliveryStr[field],id);
    }

    Thanks again,
    Rob

    travelinrob Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139