# Alternatives to eval()

**URL:** <https://discourse.nodered.org/t/alternatives-to-eval/50550>\
**Category:** General\
**Created:** [2 September 2021 20:40 UTC](https://discourse.nodered.org/t/alternatives-to-eval/50550 "2021-09-02T20:40:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 September 2021 20:51 UTC](https://discourse.nodered.org/t/alternatives-to-eval/50550/2 "2021-09-02T20:51:39Z")

</div>

Use `RED.util.getObjectProperty` to get sub properties of an object using a string

```auto
var list = { "find": { "me": [{ "in": { "this": "section" } }, { "in": { "this": "room" } }] } };
var listArray = list.find.me;
var location = "in.this";
var location2a = "in";
var location2b = "this";
var string = "section";

for (let i = 0; i < listArray.length; i++) {
    if (listArray[i].in.this == "section") {
        node.warn("found validation");
        //execute something
    }

    if (RED.util.getObjectProperty(listArray[i], location) == string) {
        node.warn("found using msg strings");
        //execute something
    }

    if (listArray[i][location2a][location2b] == string) {
        node.warn("alternative found using msg strings");
        //execute something
    }
}

```

---

_[View the full topic](https://discourse.nodered.org/t/alternatives-to-eval/50550)._
