How does js know the array variable name to get the array element?

I have two arrays in data
data: {

array = [],
text = [],
}

now I need to load the array
var type = "array";// or" text"
data.type [index] .key
so that I can report an error. How can I get it?
Thank you

May.01,2022

data[type][index].key

data[key]

if the key is a variable, you need to use square brackets. The point is not applicable


datatype.key. First of all, you need to understand that getting the elements in the array is obtained through the index. Then you have two attributes in the data object, but the array, so you first datatype.key

.
Menu