Search a list in JavaScript

0
I am trying to search a list in JavaScript. How exactly do I have to specify this? export async function UpdateVisibility(visibilityJSON, selectedValueID, smartPositionList) { // BEGIN USER CODE var PositionList = []; if (!selectedValueID) { return PositionList; } var obj = JSON.parse(visibilityJSON); for(var k in obj.visibility) { if(obj.visibility[k].SelectableEntryID == selectedValueID){ for(var j in obj.visibility[k].true) { console.log(obj.visibility[k].true[j].id); console.log(smartPositionList.find("Sequence" = obj.visibility[k].true[j].id).toString()); } } } return PositionList; // END USER CODE }  
asked
2 answers
0

The most transparent way is defining an iterator variable and then iterating over the array, like:

for (var i = 0 ; i < array.length ; i ++){
<do something like comparing attribute of object to a value>
}

There are also other ways out there, like Array.find. For those examples see other websites, like stackoverflow.


You have a JSON structure which consists from what I read of arrays (obj[k].visibility) in arrays (obj[k].visibility[j].true) but that seems illogical to me from the naming of it. 
Perhaps it is better to share the JSON structure so we can understand what you are trying to achieve.

answered
0

You might set up a test at https://jsfiddle.net/ and make it easy for us to collaborate.

As Mendix addict, why not use a nanoflow?

answered