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 replace String with user input values for storing in a variable?

Here is the code :

var raw = "{\r\n   \"__metadata\": {\r\n        \"type\": \"SP.Data.TestPostListItem\"\r\n    },\r\n    \"Title\": \"Ankit\",\r\n    \"EmpID\": \"698\"\r\n}";

I have two user input values which I want to replace.
Ankit with name and
698 with empid

I have stored the user input values using useState like 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

const [name, setName] = useState("");
const [empid, setEmpid] = useState("");

Can anyone help me with this please?

>Solution :

You just have to convert your raw string into an object:

const obj = JSON.parse(raw);

obj.Title = name;
obj.EmpId = empid;
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