ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 17 - AD0-E330 discussion

Report
Export

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); }

Answers
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); }

Answers
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); }

Answers
C.

for (var i = 0; i < query.len; i++) { logInfo(query[i].$email); }

Suggested 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.

asked 25/10/2024
mostafa khalaf
53 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first