myObj is storing the input coming from the user which is pushed to arr which is store in localStorage as a 'data' key. On submit, I want the new values to be added to arr and not overwrite it (in the else part). The following code works but overwrites the old data:
var myObj = {
    field1: fname.value,
    field2: lname.value,
    field3: birth.value,
    field4: salary.value,
    field5: String(selectedGender),
    field6: String(choicesOfHobby),
    field7: color.value,
    field8: String(choicesCountry),
    field9: textArea.value
}  
    const arr = new Array()
if (window.localStorage.length == 0) {
   const arr = JSON.stringify(myObj); 
   window.localStorage.setItem('data', arr);
} else {
    const arr = JSON.stringify(myObj); 
   window.localStorage.setItem('data', arr);
}
 
     
     
     
     
    