How to access a specific field of a dataset (solved)

Hello! I am trying to access a specific field of a dataset. I’ve searched a lot and all the examples that I’ve found use the whole array of objects. They never access a specific field of a specific object. For example:

 $w("#myDataset").getItems(3, 2) 
.then( (result) => { 
let items = result.items; 
let totalCount = result.totalCount; 
let offset = result.offset; 
} ) 
.catch( (err) => { 
let errMsg = err.message; 
let errCode = err.code; 
} ); 

I know that this code, taken from the Wix API page, gets 2 items, beggining at the index 3, and puts them in the “items” array, but let’s say that there’s a text field called “Name” for every item in my database. How could I access the “Name” field of the second item retrieved by this method that I just used above ?

Any help or guidance is appreciated!

Since you receive an array of objects, you can use standard JavaScript to access the particular property you want.

So for your case you would do something like this:

let value = item[1].name;  

Sam thanks for your reply, it worked!

Sam, I had two follow-up questions:

  1. I am assuming ‘name’ here is the Field Key or can we use the Field Name?
  2. I have a Field Key that contains a space - Recipe Name, how would I access that specific field in that case? I get unexpected token errors on my .js file when I use either of the below:

let value = item[1].[“Recipe Name”]

let value = item[1].“Recipe Name”
Thanks.

Hi,
The Field Name is just a label. If you wish to get a specific item, you should use the Field Key. I recommend checking out the video tutorial and the explanation here .

Best,
Tal.