[SOLVED] Arrays?

Hey everyone, do you know how you would make an array in rpg maker MV? Thanks!
Hi!
You can make it in the same way that is made on Javascript:
let myVariable = []

But if you mean using the game variables:
$gameVariables.setValue(ID, []);
Hi!
You can make it in the same way that is made on Javascript:
let myVariable = []

But if you mean using the game variables:
$gameVariables.setValue(ID, []);
Thanks so much, this is really helpful! But, is there a way to add a value to the array, like, there is already data in the array and you just add another value to it?
If it's in a variable, and you know it's an array already:

JavaScript:
$gameVariables.value(ID).push(newValue);

To add it to the beginning instead of the end:

JavaScript:
$gameVariables.value(ID).unshift(newValue);

Or in the middle:

JavaScript:
$gameVariables.value(ID).splice(newIndex, 0, newValue);
Oh, yes!
You can use this:
$gameVariables.value(ID).push(Value)
$gameVariables.value(ID).unshift(Value)

push > Add a new item in the final position of the array.
unshift > Add new item on the first position of the array.

But you will not be able to reference it on the message window with \v[id], it will not return the array.
But you can use:
$gameVariables.value(ID)[index]
Where the index is the value of the array position you are looking for. Always start with zero.
If it's in a variable, and you know it's an array already:

JavaScript:
$gameVariables.value(ID).push(newValue);

To add it to the beginning instead of the end:

JavaScript:
$gameVariables.value(ID).unshift(newValue);

Or in the middle:

JavaScript:
$gameVariables.value(ID).splice(newIndex, 0, newValue);
Oh, yes!
You can use this:
$gameVariables.value(ID).push(Value)
$gameVariables.value(ID).unshift(Value)

push > Add a new item in the final position of the array.
unshift > Add new item on the first position of the array.

But you will not be able to reference it on the message window with \v[id], it will not return the array.
But you can use:
$gameVariables.value(ID)[index]
Where the index is the value of the array position you are looking for. Always start with zero.
Thank you so much! This is super helpful.

EDIT: Sorry for asking so many questions, but is there a way to see if a static value is equivalent to any of the values in the array?
Yes, there is a lot of ways of doing that.
That is a simple one:
let myArray = [10, 5, 3, 'ball']
let value = 3;
let result = myArray .includes(value) // It will return true if myArray contains the value, and false otherwise.
Yes, there is a lot of ways of doing that.
That is a simple one:
let myArray = [10, 5, 3, 'ball']
let value = 3;
let result = myArray .includes(value) // It will return true if myArray contains the value, and false otherwise.
That is exactly what I needed, thanks so much!

Original thread: https://forums.rpgmakerweb.com/threads/solved-arrays.124214/