skiarsi's avatar

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?

0 likes
1 reply
coni's avatar

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
}
2 likes

Please or to participate in this conversation.