Any simple function to inserto a row into table from JS Object?
See original GitHub issueRight now I use this cumbersome approach when I want to add a row whose data is in a JS Object
Adding a row to a table:
var db = mysql.createConnection(DBInfo)
var databaseObj = {val1: '1', name: 'John', age: 40}
var query = 'INSERT INTO my_table ('
var databaseKeys = Object.keys(databaseObj)
for (let i = 0; i < databaseKeys.length; i++) {
query += databaseKeys[i] + (i !== databaseKeys.length - 1 ? ', ' : ')')
}
query += ' ' + 'VALUES('
for (let i = 0; i < databaseKeys.length; i++) {
query += '\'' + databaseObj[databaseKeys[i]] + '\'' + (i !== databaseKeys.length - 1 ? ', ' : ')')
}
db.query(query, function (err, results, fields) {...
Is there any simpler or neater way to add a row into a table, where such row data is in a JS Object?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to insert a row in an HTML table body in JavaScript
If you want to add a row into the tbody , get a reference to it and call its insertRow method. var tbodyRef...
Read more >JavaScript function to add rows to a table - w3resource
var table = document.getElementById('sampleTable'), row = table.insertRow(0), cell0 = row.insertCell(0), cell1 = row.
Read more >HTMLTableElement.insertRow() - Web APIs | MDN
The HTMLTableElement.insertRow() method inserts a new row ( <tr> ) in a given <table> , and returns a reference to the new row....
Read more >HTML DOM Table insertRow() Method - W3Schools
The insertRow() method creates an empty <tr> element and adds it to a table. The insertRow() method inserts the new row(s) at the...
Read more >Back To The Basics: How To Generate a Table With JavaScript
function generateTableHead(table, data) { let thead = table.createTHead(); let row = thead.insertRow() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is your original code written that way if it helps:
Thanks again, it worked 😃