jquery

Accessing string sub elements in a multidimensional javascript object  #angularjs #reactjs

  • obj = { “1483805300000”: [{“case”:”77222″,”note”:”Hello”}], “1483805600000”: [{“case”:”77333″,”note”:”Hello 333″}] }; for (const prop in obj) { $(‘div’).html( $(‘div’).html() + prop +’
    ‘); $(‘div’).html( $(‘div’).html() + prop.case +’
    ‘); $(‘div’).html( $(‘div’).
  • If you don’t use the arrays (brackets []) then you need to use obj[prop].case & obj[prop].
  • You need to use obj[prop][0].case & obj[prop][0].note instead of prop.case & prop[‘note’] like following.
  • remove the array wrapping each individual object and use obj[prop].

remove the array wrapping each individual object and use obj[prop].propertyName or obj[prop][‘propertyName’] to access appropriate property values

@ng_real_ninja: Accessing string sub elements in a multidimensional javascript object #angularjs #reactjs

How can I access the “case” and “note” values for each “time” key value in the below code?

why the array wrapping each individual object? – charlietfl 1 hour ago

Cause I don’t know what I’m doing : ) – gibberish 1 hour ago

Well, will there be more than one for each time value? – charlietfl 1 hour ago

Is the case/note object always the first item in the array? – cbass 1 hour ago

@charlietfl Nope, just the one. I tried it without the square brackets and that didn’t work either. After dozens of attempts its difficult to filter all attempted combinations down to one sample for the question. – gibberish 1 hour ago

obj = { “1483805300000”: [{ “case”: “77222”, “note”: “Hello” }], “1483805600000”: [{ “case”: “77333”, “note”: “Hello 333” }] }; for (const prop in obj) { $(‘div’).html($(‘div’).html() + prop + ‘
‘); $(‘div’).html($(‘div’).html() + obj[prop][0].case+’
‘); $(‘div’).html($(‘div’).html() + obj[prop][0].note + ‘
‘); }

obj = { “1483805300000”: [{“case”:”77222″,”note”:”Hello”}], “1483805600000”: [{“case”:”77333″,”note”:”Hello 333″}] }; for (const prop in obj) { $(‘div’).html( $(‘div’).html() + prop +’
‘); $(‘div’).html( $(‘div’).html() + obj[prop][0].case +’
‘); $(‘div’).html( $(‘div’).html() + obj[prop][0].note +’
‘); }

obj = { “1483805300000”: {“case”:”77222″,”note”:”Hello”}, “1483805600000”: {“case”:”77333″,”note”:”Hello 333″} }; for (const prop in obj) { $(‘div’).html( $(‘div’).html() + prop +’
‘); $(‘div’).html( $(‘div’).html() + obj[prop].case +’
‘); $(‘div’).html( $(‘div’).html() + obj[prop].note +’
‘); }

jquery