# How to clean up the data in an array?

**URL:** https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918
**Category:** Maya
**Tags:** mel
**Created:** [February 16, 2005, 8:44pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918 "2005-02-16T20:44:04Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![cooki](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cooki](https://forum.highend3d.com/u/cooki)
#### Post date: [February 16, 2005, 8:44pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/1 "2005-02-16T20:44:04Z")

</div>

I'm testing my script which has some array declaration in it. It goes like this:

string $ctrlList[] = {"ctrl1", "ctrl2", "ctrl3"};

But when I try to make a change in one of the element and re-excute it in Script Editor,ex. ctrl2--\>ctrl4, ctrl2 wasn't replaced by ctrl4. If I print out the array, it's like

ctrl1  
ctrl2  
ctrl3  
ctrl1  
ctrl4  
ctrl3

is there something i can do to clean it up first? otherwise I have to restart maya everytime for testing it... ![](http://www.highend3d.com/boards/style_emoticons/<#EMO_DIR#>/sleep.gif)

thax

cooki

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [February 16, 2005, 10:38pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/2 "2005-02-16T22:38:12Z")

</div>

{  
string $ctrlList[];  
//...etc  
}

---

<div class="post-metadata">

### Author: ![cooki](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cooki](https://forum.highend3d.com/u/cooki)
#### Post date: [February 16, 2005, 11:40pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/3 "2005-02-16T23:40:22Z")

</div>

how could I not think of this. thax~

---

<div class="post-metadata">

### Author: ![cooki](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cooki](https://forum.highend3d.com/u/cooki)
#### Post date: [February 17, 2005, 12:21am UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/4 "2005-02-17T00:21:46Z")

</div>

I have a new problem now....now the data is right, but seems like there are lots of empty space in the begining. so when I try to get the 1st element in the array, it returns nothing. If I print it out, it's like:

ctrl1  
ctrl2  
ctrl3

does anyone have the same problem?

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [February 17, 2005, 12:44am UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/5 "2005-02-17T00:44:25Z")

</div>

You've probably put empty strings in the array. So it doesn't return _nothing_, it returns empty string. You can remove array elements using stringArrayRemove

string $result[] = stringArrayRemove( { "" }, $array );

---

<div class="post-metadata">

### Author: ![cooki](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cooki](https://forum.highend3d.com/u/cooki)
#### Post date: [February 17, 2005, 5:06pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/6 "2005-02-17T17:06:13Z")

</div>

thanks a lot again !!

---

<div class="post-metadata">

### Author: ![catalin-niculescu](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/d2c977/32.png) [@catalin-niculescu](https://forum.highend3d.com/u/catalin-niculescu)
#### Post date: [February 17, 2005, 9:37pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/7 "2005-02-17T21:37:49Z")

</div>

Why not  
clear $ctrlList;  
?

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [February 17, 2005, 10:39pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/8 "2005-02-17T22:39:34Z")

</div>

yes it make the variable 0 long but odesnt delete it. Its not somehthing you would want to use to replace scope, or in other words the "{}" block

---

<div class="post-metadata">

### Author: ![cooki](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cooki](https://forum.highend3d.com/u/cooki)
#### Post date: [February 18, 2005, 6:58pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/9 "2005-02-18T18:58:57Z")

</div>

another quick question. how do u clear and erase all the variables(arrays, data type) when u debug in script editor?

thax again

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [February 18, 2005, 10:36pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/10 "2005-02-18T22:36:51Z")

</div>

You can't delete global variables. Always use scope as described before.

---

<div class="post-metadata">

### Author: ![cooki](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@cooki](https://forum.highend3d.com/u/cooki)
#### Post date: [February 20, 2005, 11:48pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/11 "2005-02-20T23:48:50Z")

</div>

does that mean if I want reassign the data type (like change it from string to string[]), I have to restart maya again?

---

<div class="post-metadata">

### Author: ![failure](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/f08c70/32.png) [@failure](https://forum.highend3d.com/u/failure)
#### Post date: [February 21, 2005, 12:34am UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/12 "2005-02-21T00:34:35Z")

</div>

Yes

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [February 21, 2005, 7:23pm UTC](https://forum.highend3d.com/t/how-to-clean-up-the-data-in-an-array/3918/13 "2005-02-21T19:23:11Z")

</div>

Dont make global variables out of them. Let them die and create them anew for soome optionvars instead.

And yes this is actualy the basis of maya variables that you CANT reassign variables once they are declared they die whan their scope dies (and for global vars tahat means whan maya quits). Thats why you use names taht arent likely to reoccour for globals.
