Review the code below and mark the correct option:
javascript
Copy code
var query = NLWS.xtkQueryDef.create({
queryDef: {
schema: ‘nms:recipient’,
operation: ‘select’,
lineCount: ‘5’,
select: { node: [
{expr: ‘@firstName’},
{expr: ‘@lastName’},
{expr: ‘@email’}
]}
}
}).ExecuteQuery().getElements();
What would be the correct code to retrieve the email for each record?
A . for (var i = 0; i < query.length; i++) { logInfo(query[i].$email); }
B . for (var i = 0; i < query; i++) { logInfo(query[i].$email); }
C . for (var i = 0; i < query.len; i++) { logInfo(query[i].$email); }
Answer: A
Explanation:
In this JavaScript code snippet, the developer has queried recipient data, selecting the first name, last name, and email from the nms:recipient schema. To retrieve and log each email address from the query results, they need to loop through the returned array:
Query Result:
The result of ExecuteQuery().getElements() is an array of objects, where each object represents a record with selected fields (in this case, @firstName, @lastName, and @email).
Correct Loop Syntax:
The correct syntax for looping through an array in JavaScript involves using .length to determine the number of elements in the array. Therefore, for (var i = 0; i < query.length; i++) is the correct loop structure.
Accessing the Email Field:
Within each record object, logInfo(query[i].$email); accesses the $email property and logs it. This syntax correctly refers to each record’s email field within the loop.
Option A is correct because it accurately loops through the query results and retrieves each email address using the $email attribute.
Latest AD0-E330 Dumps Valid Version with 50 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund