Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

AlpineJS - How to watch an object property which is an array ?

Hello,

I have an studies array which contains several study and each study has the following properties : year (number) and diplomas (array).

studies.push({
	'year': 2020,
	'diplomas': ['diploma 1', 'diploma 2'],
});

...

$watch('studies', value => console.log(value));

When I change a diploma in the form, I have no console log.

How is it possible to watch to any change inside the diplomas array ?

Thanks for your help ;).

V

0 likes
2 replies
toroterminator's avatar

assuming you have

<div x-init="$watch('studies', value => console.log(value));" x-data="{studies:[]}">

and then the push happens somewhere after init ?

1 like

Please or to participate in this conversation.