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

Create a new key and or array to existing object in node.js

I have an existing object called unsettled:

var unsettled =
    {
        processor: 1,
        dayFrom: 10,
        dayTo: 12
    }

Im trying to add an object called pName as I do with Angular, but it is not working.

unsettled.pname = "something"

It does work if unsettled.pname already exists on the object, but not if I want to create it.

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

Also, after a sql Query where I get several results, I need to create an array. Same thing, when I do

const pool = await utils.poolPromise
        const recordset = await pool.request()
            .query(sqlString)
        if (recordset.rowsAffected[0] > 0) {
            unsettled.processors = recordset.recordset;
        }

Is not working either (the array processors is not being created).

Thanks.

>Solution :

For the array, try:

    if (recordset.rowsAffected[0] > 0) {
        unsettled["processors"] = recordset.recordset;
    }

As for as pName, please try

unsettled["pname"] = "something"
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