VMware Aria Automation Orchestrator

 View Only

Orhestrator JS syntax for finding an element in a Properties array by property value

  • 1.  Orhestrator JS syntax for finding an element in a Properties array by property value

    Posted 12 days ago

    Here are two JavaScript samples for finding an array element by element value:

    const products = [
      { name: "Laptop", category: "Electronics" },
      { name: "Shirt", category: "Apparel" },
      { name: "Phone", category: "Electronics" }
    ];

    const electronics = products.filter(item => item.category === "Electronics");

    System.log(electronics);

    const employees = [
      { id: 101, name: "Alice" },
      { id: 102, name: "Bob" },
      { id: 103, name: "Charlie" }
    ];

    // Find the object where id equals 102
    const match = employees.filter(item => item.id === 102);

    System.log(match);
    Both of these snippets work on any modern JavaScript implementation. But the syntax is different in Aria's ancient Rhino implementation. Can you help me find the right syntax? 
    I got the search to work with foreach loop. But it's pretty klunky. Is there a one-line way to do this in Orhcestrator?
    for(item in propertiesArray){
        if(propertiesArray[item].property == 1234){System.log(propertiesArray[item]);}
    }