1

I am trying to add another property to each object I receive from the DynamoDB table. I am trying to do this by altering each object in the Items array then adding the Items array to my responseBody. All I get in return is the original items without any new properties. This could be a product of me using the array functions or spread operator incorrectly, just kindly point out anything you may see. My lambda function is below:

const data = await documentClient.scan(params).promise();
    data.Items.map(item => {
      item = {
        ...item,
        control: control_id
      };
    });
responseBody = JSON.stringify(data.Items);

UPDATE: I solved my issue above by doing the following:

const data = await documentClient.scan(params).promise();
    data.Items.forEach(item => {
      item.control = control_id;
    });
responseBody = JSON.stringify(data);

1 Answer 1

2

Javascript Array Map return new array. see Array Map

Sign up to request clarification or add additional context in comments.

1 Comment

okay, got it. I was under the impression it was altering it. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.