-5

I want to create a jQuery below format with help of using two each statements.

arrar [
  'aaa'=>'ccsdfccc',
  'bb'=>'aaddsaaaa',
  '1'=>[
      'three'=>'sdsds'
      'four'=>'eesdsee'
       ] 
  '2'=>[
      'one'=>'dcvcdd'
      'two'=>'eeee'
       ] 
    ]
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shanmuga kumar
  • 165
  • 1
  • 4
  • 12

1 Answers1

0

In javascript there are 2 type of arrays: standard arrays and associative arrays

  • [ ] - standard array - 0 based integer indexes only
  • { } - associative array - javascript objects where keys can be any strings

So when you define:

var arr = [ 0, 1, 2, 3 ];

you are defining a standard array where indexes can only be integers.

So you can write this object

var obj = {
    'aaa': 'ccsdfccc',
    'bb': 'aaddsaaaa',
    '1': {
        'three': 'sdsds',
        'four': 'eesdsee'
    },
    '2': {
        'one': 'dcvcdd',
        'two': 'eeee'
    }
}

and then use it like obj['1'].three

ashkufaraz
  • 5,179
  • 6
  • 51
  • 82