Consider this setup where we have two arrays. Let’s see how to extract specific data from these arrays using the Javascript node.
In the Javascript node, configure the Inputs
and Outputs
tab in the Editor
panel:
Code
Here is the script in the Main section of the Script
tab :
output_1 = input_2
output_2 = input_1["bbb:x"]
output_3 = input_2_ids[0]
output_4 = input_1_ids[1]
output_5 = input_2_propertiesName[2]
Detail
Let’s detail line by line how we configured our outputs using javascript :
output_1 = input_2
: In output_1 we’ll output whatever we plug into input_2 as is, without modification.
output_2 = input_1["bbb:x"]
: In output_2 we’ll look into our input_1 for an ID namedbbb
and for that ID we’ll extract whatever value is held by the property namedx
.
Note : If the IDbbb
does not exist in the input, or if it does not have a property namedx
then the output will be empty.
output_3 = input_2_ids[0]
: In output_3 we’ll look into our input_2 and extract the ID for the index 0.
output_4 = input_1_ids[1]
: In output_4 we’ll look into our input_1 and extract the ID for the index 1.
output_5 = input_2_propertiesName[2]
: In output_5 we’ll look into our input_2 and extract the name of the third property.
Note : Properties, like indexes, are numbered starting from 0. Hence,propertiesName[2]
points to property number 3, and not number 2.
Need more help with this?
Don’t hesitate to contact us here.