Queries return an array results. How I can get a specific field data from the results. In the below example, how I can extract from the “firstItem” or the “results.items” just the first name or last name?
wixData.query(“myCollection”)
.find() .then( (results) => { let firstItem = results.items[0]; //see item below } )
/* firstItem is:
*
- {
- “_id”: “00001”, .
- “_owner”: “ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb”,
- “_createdDate”: “2017-05-24T12:33:18.938Z”,
- “_updatedDate”: “2017-05-24T12:33:18.938Z”,
- “title”: “Mr.”,
- “first_name”: “John”,
- “last_name”: “Doe” * }
*/
Do either firstItem.first_name or results.items[0].first_name and either firstItem.last_name or results.items[0].last_name work for you?
Thanks!!! It works perfectly…
Thanks
can someone tell me how to get the first_Name from the result item ?
Something like this…
let firstName = results.items[0].first_Name
“first_Name” <------ this should be the column-ID (reference)
But if you have an issue/problem, then feel free to open your own post-request, do not reopen old posts.
You can also look here …
…to get codes like this…
import wixData from 'wix-data';
wixData.query("myCollection") // <--- here your database-name
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0]; //see item below
let firstName = results.items[0].first_Name
console.log(firstName)
} else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
} );