Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to update argument's value of list in JavaScript

hi i have a list with three empty object like :

TimePickerList =[{},{},{}];

and for Example i want to add 1 and 2 to first argument of this list like :

TimePickerList[0].push("1") // i know it's wrong way and i cant use push like this .
TimePickerList[0].push("2")

and i want to get this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TimePickerList =[{"1","2"},{},{}];

is there any way to do this? i mean can i update argumant value?

>Solution :

You can update values stored in arrays like such:


TimePickerList = [{}, {}, {}];

TimePickerList[0].a = 1;

console.log(TimePickerList)
   // [{ a: 1 }, {}, {}]

The reason it wasn’t working for you is because you were trying to push a value to an object. If you want to push values then push to an array, therefore using square brackets [] instead of curly braces {}.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading