Syntaxe for getting the field value of an array

Question:
My code gives me an array with just one row, but several columns:
_i* d

  • title
  • _owner
  • image
  • _createdDate
  • and so on

Product:
Wix Editor with velo Wix

What are you trying to achieve:
When I click to an image of my repeater, I want a specific action regards to the owner of the clicked item

What have you already tried:
velo assistance, wix helper wix studio forum and javascripts forum, https://shoonia.site

Additional information:
Here is my code:

import wixData from 'wix-data';
import wixUsers from 'wix-users';

// Scope pour traiter un item selectionné par clic sur une image
// vu sur https://shoonia.site/event-handling-of-repeater-item/

const createScope = (getData) => (event) => {
    const itemId = event.context.itemId;
    const find = (i) => i._id === itemId;
    return {
        $item: $w.at(event.context),

        get itemData() {
            return getData().find(find);
        },
    };
};

const useScope = createScope(() => {
    return $w("#listRepeater").data;
});

// début du traitement de la page

$w.onReady(function () {

    $w("#dataset1").onReady(() => {
        $w('#image').onClick((event) => {

            const { itemData } = useScope(event);
            console.log(itemData)
        });
    })
})

itemData is exactly what I expect (thanks to https://shoonia.site, with the whole properties of my item, I show you a screen capture:

But now, I don’t jnow how to use the value of the fields, for instance the field “marque”
I don’t know the syntax, and have found nothing useful.

I have tried many things, like
console.log(itemData.marque)
console.log(itemData[0].marque)


Nothing works.

I am sure that it is evident, but no way to find it.

Thank you for your help !

That is not an array, it is an object

Objects are complex data types that have values assigned to custom property indexes:

const someObject = {
    someProperty: 'some value', 
    anotherProperty: 'another value',
    'multi word property': {
        something: 'something'
    }
}

You can access a property of an object in two methods:

  1. Dot notation: someObject.someProperty - results in ‘some value’
  2. Bracket notation: someObject['multi word property'].something - results in ‘something’

Multi word properties can only be accessed using the bracket notation


Arrays are lists of values by index: [value0, value1, value2, value3...], accessing an item on an array is done through its index: array[0] gives the first item in the array

OK I could have searched for a long time!

Here is the result copied from my console.log(itemData):

{
  "picesManquantes": 0,
  "_publishDate": "Sat Nov 23 2024 06:36:03 GMT+0100 (heure normale d’Europe centrale)",
  "link-liste-all": "/liste/",
  "marque": "RAVENSBURGER",
  "image": "wix:image://v1/9820d4_9f18243eed244576a292bd6c07c112ed~mv2.jpg/triomphedelareligion_edited.jpg#originWidth=1000&originHeight=750",
  "_id": "ca6259f7-7ed9-4d8d-8b9e-840f189a41b9",
  "_draftDate": "null",
  "_owner": "9820d4d0-34e4-4f86-b13c-53e3b0798064",
  "_createdDate": "Sat Nov 23 2024 06:36:03 GMT+0100 (heure normale d’Europe centrale)",
  "_updatedDate": "Tue Nov 26 2024 11:25:02 GMT+0100 (heure normale d’Europe centrale)",
  "link-liste-title": "/liste/ca6259f7-7ed9-4d8d-8b9e-840f189a41b9",
  "link-copy-of-liste-title": "/liste-lecture/ca6259f7-7ed9-4d8d-8b9e-840f189a41b9",
  "nombreDePices": 3000,
  "range": "7) autour de 3000",
  "status": "non disponible",
  "_publishStatus": "PUBLISHED",
  "owner": "9820d4d0-34e4-4f86-b13c-53e3b0798064",
  "title": "Le triomphe de la religion",
  "link-liste-1-title": "/liste-1/le-triomphe-de-la-religion",
  "kilegere": "arenseigner@nul.fr",
  "createdDate": "Sat Nov 23 2024 00:00:00 GMT+0100 (heure normale d’Europe centrale)"
}

I suppose that someObject is itemData
and someProperty is marque or _id for instance

So someObject.someProperty should be itemData.marque

But console.log(itemData.marque) displays “undefined”

II still don’t understand very well, sorry, but thank you for your help!

If this is the result of console.log(itemData), then console.log(itemData.marque) should definitely return the contents within the marque property, that is, “RAVENSBURGER”

Hving been returned as undefined, something must be wrong, are you absolutely sure the lines run in the same context?
Would you put both log lines one right after the other?

console.log(itemData)
console.log(itemData.marque)

Perhaps you’re running the log line in the wrong scope, where itemData is not defined?

1 Like

I thought I had tried it many times
 but not.

So I’m glad to tell you: IT WORKS ! and that was very simple, indeed.

Thank you very much, you are the best!

1 Like

Glad to have helped :slight_smile: