I'm trying to inject an array of one key objects into a hidden input for a form so that when I submit the form, it returns the contents of the array in a way I can spread into a new array using .split. However, when I check the values of the input, it shows the contents as [object Object], [object Object], ... even though the actual array may look like [{test: 1}, {test2: 1}, ...]. How do I get the objects to essentially spread into the value for the input?
var sprints = [];
function newSprint() {
var li = document.createElement("li");
li.className = "color1";
li.setAttribute("onclick", "this.classList.toggle('checked')")
var inputValue = document.getElementById("sprints-input").value;
li.innerHTML = inputValue
if (inputValue === '') {
alert("You must write something!");
} else {
document.getElementById("sUL").appendChild(li);
var sprintInput = document.getElementById("sprints");
li.setAttribute("data-name", inputValue);
sprints.push({[inputValue]: 1});
sprintInput.value = sprints;
}
the sprintInput is where I'm trying to inject my array of objects, sprints. I've also tried ... to spread it but it doesn't seem to work in browser code as it reffers to it as an unrecognized token.