Hello! On js from JSON, I restored an object of the following form:

{"1":{"108":{"3":"605500","6":"785000"},"113":{"6":"60000"}}} 

Tell me, please, how can I add new values ​​to it?

  • Here it is: "108":"3":"605500" - incorrect JSON, if that. - Zhukov Roman
  • was wrong corrected - masha2
  • one
  • Thank you all, I don’t know if I’ve done it correctly or not, but it works: function save_prices_to_array (titles_of_prices_table_ph, i_p_p_e_ar_p_e_ar_p_e_ar_e_ar_p_e_ar_e_ar_p_e_ar_p_e_ar_p_e_ar_e_ar_e_ar_p_e_array), {i () if (! (ID_dv_k_p in js_conveniently_model_prices [titles_of_prices_table_ID])) {js_conveniently_model_prices [titles_of_prices_table_ID] [ID_dv_k_p] = new Object ();}; js_conveniently_model_prices [titles_of_prices_table_ID] [ID_dv_k_p] [ID_kompl_for_prices] = elem.value; }; - masha2

2 answers 2

Well, first, give it a name:

 var sampleObj = {"1":{"108":"605500","6":"785000"},"113":{"6":"60000"}}; 

And then - as you like:

 sampleObj['2'] = 3; sampleObj.s = 15; 
  • I tried this; in this case, when I try to assign a new value, I get the error Uncaught TypeError: - masha2
  • old values ​​are thus corrected without problems - masha2
  • @Mariya, when referring to the properties of an object, it is necessary to write like this: js_conveniently_model_prices['1']['112']['3']=5; - Zhukov Roman
  • oh, I have it, it hurried to recruit here - masha2
  • So you do not have the property js_conveniently_model_prices['1']['112'] - Zhukov Roman

Translate to json object, add values, translate to string.

You can still be perverted with parsing, but it is likely to spoil everything.

  • No, I don’t know exactly how to add a value - masha2
  • sampleObj ["2"] = 3; As written below. Only necessarily, necessarily quotes and, suddenly, brackets, like an array. - knes
  • @knes, thanks, hurried and sealed. - Zhukov Roman