-1

I did not find the syntax to do this.

Some unsuccessful attempts:

TILESETS[actualTileSetNO].tiles

One inconvenient but working way:

//access an object which is a specific row of the array

let x=TILESETS[actualTileSetNO];

//access the array that is within the object

let y=x.tiles;

__ update: My syntax was good, but I think the property was not existing yet (loaded by a promise). It works if I do:

  if (typeof(state.TILESETS[state.actualTileSetNO]) !=='undefined') {
  return state.TILESETS[state.actualTileSetNO].tls} 
  else {return null}

I do not see a way to close the case or flag it as an answer.

EMHmark7
  • 87
  • 8

3 Answers3

0

Checkout the following code snippet -

Assuming this might be the array structure.

let arr = [{

  arr1: ['a', 'b', 'c', 'd']
}]

console.log(arr[0].arr1);

if arr is your main array which has a couple of objects in it. Access them by using the index which will fetch you that particular object and within it, to access another array, you can use it by referring it to it's key.

0

If you have an array of objects, you should be able to access the properties of the object using the syntax you described:

TILESETS[actualTileSetNO].tiles;

e.g

const TILESETS = [
    { tiles: [1, 2, 3] },
    { tiles: [2, 4, 5] }
];

console.log(TILESETS[0].tiles[1]);
// prints 2

If this doesn't work for you, perhaps the problem is elsewhere. Could you post more of your code?

0

did you mean this here? let me know if this helps you!

arrName[arrItem].objectPropertyName[subArrItem]

var myArr = [
  {
   a:[1,2,3,4], 
   b:[5,6,7,8], 
   c:[9,10,11,12]
  },
  {
   d:[13,14,15,16],
   e:[16,18,19,20], 
   f:[21,22,23,24]
  }
 ]
 
 console.log(myArr[1].f[3])
Helmer Barcos
  • 1,898
  • 12
  • 18