Mytask
Mytask
Split the given array in 3 numbers and display in a table html page
Array:
[“ha”,“hi”,“hq”,“he”,“hr”,“hm”,“hn”,“hd”,“he”,”hg”]
Output:
[ha, hi, hq] [he,hr,hm] [hn,hd,he][hg]
numbers.forEach((chunk) => {
const row = tbody.insertRow();
chunk.forEach((string) => {
const cell = row.insertCell();
cell.innerText = string;
});
});
document.getElementById('table-container').appendChild(table);
2. Check if “test2” exists in the given object array, if it exists print the index
of the object and the matched object:
Object:
[{id:1,”name”:”test”},{id:2,”name”:”test2”},{id:3,”name”:”test3”}]
Output:
Index: 1
Object: {id:2,”name”:”test2”}
output:
[0,1,2,3,4,5]
var a = "['0'-'1'-'2'-'3'+'4'+'5']";
a = a.replace(/[^\w\s]/gi, '');
var myarr = a.split('')
const result = myarr.map(x=>Number(x))
console.log(result)
Output:
[0, 1, 2, 3, 4, 5]
4. Create a dynamic table. on click of a button the table rows with text field
should be added
<table id="myTable">
<thead>
<tr>
<th>S.No</th>
<th>Name</th>
<th>Age</th>
<th>DOB</th>
<th>Email</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><input type="text" name="textfield1"></td>
<td><input type="text" name="textfield2"></td>
<td><input type="text" name="textfield3"></td>
<td><input type="text" name="textfield4"></td>
<td><input type="text" name="textfield5"></td>
</tr>
</tbody>
</table>
function addRow() {
var table = document.getElementById("myTable");
var rowNumber = table.rows.length;
var row = table.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
cell1.innerHTML = rowNumber;
cell2.innerHTML = '<input type="text" name="Name' + rowNumber + '">';
cell3.innerHTML = '<input type="text" name="Age' + rowNumber + '">';
cell4.innerHTML = '<input type="text" name="Dob' + rowNumber + '">';
cell5.innerHTML = '<input type="text" name="Email' + rowNumber + '">';
cell6.innerHTML = '<input type="text" name="Comment' + rowNumber + '">';
}
<div id="myDiv">
</div>
<div id="form-content"></div>
var a ={'Test':
[{
id:1,'name':'test1','menu':'Test'
},{
id:1,'name':'test2','menu':'Test'
},{
id:1,'name':'test3','menu':'Test'
}],'Test2':
[{
id:1,'name':'test21','menu':'Test1'
},{
id:1,'name':'test22','menu':'Test1'
},{
id:1,'name':'test23','menu':'Test1'
}],'Test3':
[{
id:1,'name':'test31','menu':'Test2'
},{
id:1,'name':'test32','menu':'Test2'
},{
id:1,'name':'test33','menu':'Test2'
}]}
for(const x in a ){
const div = document.getElementById('myDiv')
const name = a[x]
const mybtn = document.createElement("button");
mybtn.textContent = testType;
mybtn.onclick = function() {
displayButtons(name);
};
div.appendChild(mybtn);
function displayButtons(name) {
const testContent= document.getElementById("form-content");
testContent.innerHTML = "";
show.forEach(x => {
const testHtml = `
<div class="form-detail">
<p><b>Form ID</b>: ${x.id}</p>
<p><b>Form Name</b>: ${x.name}</p>
<p><b>Form Type:</b> ${x.menu}</p>
</div>
`;
testContent.innerHTML += testHtml;
});
}