Send an array with Inertia
Hey Laravers.
In this part of code I'm trying to send an array to database with Inertia.
const datas = [];
datas['color']=color;
datas['title']=title;
datas['text'] = text;
router.post(route("home.newnote", datas));
When I'm using this code, It sends null, but when I change last line to:
router.post(route("home.newnote", [{'color': color, 'title': title,'text': text}]));
It's working fine and send all datas.
Can you please tell me why it's happening, please?
It is because JavaScript does not support associative arrays. If you try:
const datas = [];
datas[0] = color;
datas[1] = title;
datas[2] = text;
it will work, but naturally send it as an object:
const datas = {
color: color,
title: title,
text: text
}
Please or to participate in this conversation.