variable as index in an associative array - Javascript

前端 未结 7 1272
时光说笑
时光说笑 2021-02-03 23:39

I\'m trying to create an associative array, create an empty array, and then add a (indexName -> value) pair:

var arrayName = new Array;

arrayName[\         


        
7条回答
  •  再見小時候
    2021-02-04 00:06

    I did something like like following;

    let parentArray = [];
    let childArray = [1, 2, 3];
    childArray.name = 'my-array-1';
    parentArray.push(childArray);
    

    To access that by name in ES6;

    parentArray.filter(x => x.name == 'my-array-1');
    

提交回复
热议问题