I've made a constructor for an object called "Book". I've captured all the values from a form in an array. Now I want to assign the values of this array to this constructor. However, I'm quite stuck because I don't seem to find what I'm looking for on Google or StackOverflow.
Here's my code:
let formArray = [];
document.querySelectorAll('input[type="text"]').forEach(function (node) {
formArray.push(node.value);
});
let newBook = new Book();
let idx = 0;
Object.keys(newBook).forEach(function (k) {
k = formArray[idx];
})
However, this is my log:
Book {title: undefined, author: undefined, nPages: undefined, isRead: undefined}
title: undefined
author: undefined
nPages: undefined
isRead: undefined
Please help me figure this out!
formArray.push(node.value)works as expected,console.log(formArray)returns:["1", "1", "1", "1"](for example).