I am trying to create an array of key / value pairs using the push method, but I get unexpected results.
console.log prints this:
books: [{"bookTitle": "Mark Twain"}]
While I would expect this:
books: [{"Tom Sawyer": "Mark Twain"}]
Here is the code:
var books = []; var bookTitle = "Tom Sawyer"; var author = "Mark Twain"; books.push({bookTitle : author}) console.log("books: %s", JSON.stringify(books))
I tried books.bookTitle = author and books[bookTitle] = author , but the result is the same. Any help is appreciated.
source share