0

I have a doubt in Key-value pair object. I need to create a key value pair and then I need to update it.

Example: I have to create the following kind of object:

var itemval = {
   Id:1{Name:aa,Idval:1},
   Id:2{Name:bb,Idval:2},
   Id:3{Name:cc,Idval:3},
   Id:4{Name:dd,Idval:4}
}

During update I need to check the Id. If Id matches then add item in that section.

Below example Id is 1 so we are adding value in it.

var itemval = {
   {Id:1{Name:aa,Idval:1},{Name:ee,Idval:5}}, 
   Id:2{Name:bb,Idval:2},
   Id:3{Name:cc,Idval:3},
   Id:4{Name:dd,Idval:4}
}

This value I need to store it in SharePoint list column as JSON object using pnp.js.

Can someone assist me?

Thanks

1 Answer 1

0

There is a problem with your sample object.
You could use for...in to get all object key an value.

for (var key in itemval){
    console.log(key +':'+ itemval[key])
}

Pnp js add new item:

sp.web.lists.getByTitle("My List").items.add({
  Title: "Title",
  Description: "Description"
});

You could get official demo here:https://pnp.github.io/pnpjs/sp/items/#add-items

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.