What is an item?

I wish to get a specific element (item) from a collection, more precisely a specific number from the latest user input. I have connected the inputs to a database called TestData, see pic


In the above the latest inputted input is line 1. Is the item the entire line and the item id 1? If this is true how come results is not outputted in the console window, using the following code?

wixData.get("Testdata", "00001")
    .then( (results) => {
 let item = results; //see item below
        console.log(results);
    } )
    .catch( (err) => {
 let errorMsg = err;
    } );

Kind Regards
Erik

#item #itemid #wixData #collection

The returned results contains an array of items. You want this:

let items = results.items;
console.log(items);    // you can now see all of your returned items

You can then retrieve individual items (rows) by indexing the array:

let firstItem = items[0];
let secondItem = items[1];

If you expect more than one item in the returned results, you will probably want to retrieve them in a loop.

This is somehow not working, nothing is displaying. Any idears?

wixData.get("TestData" , "00001")
  .then( (results) => {
 let items = results.items;
    console.log(items);
  } )
  .catch( (err) => {
 let errorMsg = err;
  } );

@erik Hmm, so my previous answer wasn’t quite right - didn’t notice that you were doing a get().

Your original code is correct, but you need to make sure that you have an item with the _id equal to ‘00001’. Or better, you need to do the get for an id that you know exists in the collection. Look in the _id field of the collection, copy a value from one item, and use that in yoiur query. Your original code shoiuld work:

let id = < use a value from the _id field for an item (row) >
wixData.get("TestData" , id)
  .then( (results) => {
    console.log(results);
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

@yisrael-wix Okay I have written a new code better suited.

$w.onReady( () => {  
  $w("#dataset1").onReady( () => {
    $w("#dataset1").getItems(0, 1)
      .then( (result) => {
 let items = result.items;
 let userpostalcode = items[3];
        console.log(userpostalcode);
      } )
      .catch( (err) => {
 let errMsg = err.message;
 let errCode = err.code;
      } );

  } );  

Here “items” should contain the items of the first row in my data collection. The userpostalcode is however displayed as undefined. How can this be?

I now realize why the above dosenot work. It’s because items[#somenumber] returns the entire row. as sow:

0: 
"{\"_id\":\"2c8b9e6a-86c4-40d8-abca-7af3e70eb679\",\"_owner\":\"7b60316e-8162-487c-abd5-ae68e4331f54\",\"_createdDate\":\"2019-04-05T10:09:40.680Z\",\"_updatedDate\":\"2019-04-05T10:09:40.680Z\",\"postalCode\":1300,\"lastName\":\"Med  dato\",\"firstName\":\"Test\",\"addresLine\":\"Datovej\"}" 

items[0] is then equal the above.

The question now is how do I get only the postalCode?

@erik Like this:

let item = items[0];
let postalCode = item.postalCode;