# Convert string to array path?

**URL:** <https://forum.kirupa.com/t/convert-string-to-array-path/264456>\
**Category:** Uncategorized\
**Created:** [June 26, 2008, 9:13am UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456 "2008-06-26T09:13:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![skojdk](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@skojdk](https://forum.kirupa.com/u/skojdk)\
**Post date:** [June 26, 2008, 9:13am UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/1 "2008-06-26T09:13:07Z")

</div>

is it possible to do this? And if so how? :hat:

the xml is converted to an Object using XLEFF;  
there are five nodes en the specified path:

var path:String = “mCb.mXMLloaderObj.dm.lang[0].menu[0].node.length”;

trace(path)

this will offcourse output just the path as a string. But I want to trace something like:

trace(Object(path)); and hopefully get the number 5, which represents how many nodes there are in the specified path in the Object.

Is this possibly? Because I can’t find anyway to do this… Help would be much appreciated as I am on a deadline here… 😑

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 26, 2008, 9:17am UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/2 "2008-06-26T09:17:55Z")

</div>

why are you making a string in the first place?

---

<div class="post-metadata">

**Author:** ![skojdk](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@skojdk](https://forum.kirupa.com/u/skojdk)\
**Post date:** [June 26, 2008, 9:24am UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/3 "2008-06-26T09:24:20Z")

</div>

I’m building an XML based menu system and I need to be able to pass the path to different functions, that’s why I made it a string in the first place. Or is there a more convenient soulution perhaps?

:mario:

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 26, 2008, 9:42am UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/4 "2008-06-26T09:42:10Z")

</div>

well two variables; one string, one not?

why do you want to pass the object\_path as a string to different functions?

you want the stuff you get from the path, not the path itself

---

<div class="post-metadata">

**Author:** ![skojdk](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@skojdk](https://forum.kirupa.com/u/skojdk)\
**Post date:** [June 26, 2008, 9:47am UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/5 "2008-06-26T09:47:19Z")

</div>

So I should pass the object I get from the path instead of the path itself you suggest?

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)\
**Post date:** [June 27, 2008, 12:04pm UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/6 "2008-06-27T12:04:14Z")

</div>

Use **_eval_**.

```auto
var obj:Object = {subobj:{arr:[1,2,3,4,5,6,7]}};
var path:String = "obj.subobj.arr.length";
trace(path);//output obj.subobj.arr.length
trace(eval(path));//output 7

```

Cheers (-:

---

<div class="post-metadata">

**Author:** ![skojdk](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@skojdk](https://forum.kirupa.com/u/skojdk)\
**Post date:** [July 2, 2008, 3:00pm UTC](https://forum.kirupa.com/t/convert-string-to-array-path/264456/7 "2008-07-02T15:00:48Z")

</div>

cool. thanks alot
