skip to Main Content

Javascript – How to iterate multiple arrays into table rows?

var MyArray = [['Cats', ['Lion','Tiger','Leopard']], ['Dogs', ['Wolf','Pug']], ['Reptiles', ['Snake','Gecko','Lizard','Triceratops']]]; var MyTable = document.getElementById("results"); const headerRow = document.createElement("tr"); MyTable.appendChild(headerRow); for(var i=0;i<MyArray.length;i++) { const newCell = document.createElement("th"); newCell.textContent = MyArray[i][0]; headerRow.appendChild(newCell); for (const datum of MyArray[i][1]) { const newRow = document.createElement("tr"); MyTable.appendChild(newRow);…

VIEW QUESTION

Jsonata filter group by parent element

I have json object as follows {"resources":[{"srno":"1","name":"name1","projects":[{"prjname":"abc"}]},{"srno":"1","name":"name1","projects":[{"prjname":"def"}]},{"srno":"2","name":"name2","projects":[{"prjname":"abc"}]},{"srno":"4","name":"name4","projects":[{"prjname":"prq"}]},{"srno":"4","name":"name4","projects":[{"prjname":"stu"}]},{"srno":"4","name":"name4","projects":[{"prjname":"uvw"}]},{"srno":"5","name":"name5"}]} How can I get resources grouped by id,name - each of that should contain list of projects? basically,flattened to structured i.e. {"resources":[{"srno":"1","name":"name1","projects":[{"prjname":"abc"},{"prjname":"def"}]},{"srno":"2","name":"name2","projects":[{"prjname":"abc"}]},{"srno":"4","name":"name4","projects":[{"prjname":"prq"},{"prjname":"stu"},{"prjname":"uvw"}]},{"srno":"5","name":"name5"}]} can someone share jsonata expression to create same

VIEW QUESTION

Html – array.reverse() in my *ngFor don't work in production

I don't know why, when I interact with my textarea, my _messagesList is reverse ASC and DESC everytime. <div class="chat__messages"> <div *ngFor="let message of authService._messagesList.reverse()" [@fadeInOut] class="message" [ngClass]="session.User.id == message.Id_Sender ? 'myMsg' : 'otherMsg'"> <p>{{message.Content}}</p> <span>{{message.createdAt | date: "HH:mm"}}</span> </div>…

VIEW QUESTION

Javascript – sorting an array with unique scenario

I have a problem with sorting arrays in javascript: My original array: let orginalArray = ["Apple","apple","Acrobat","Account","account","Banana","banana","carrot","Carrot",1,2]; Looking for an output like this: sortedArray = ["Account","Acrobat","Apple","account","apple","Banana","banana","Carrot","carrot",1,2]; This is what I tried: let sortedArray = orginalArray; sortedArray.sort((a, b) => a[keyname].toString().localeCompare(b[keyname].toString(),'en', { caseFirst:…

VIEW QUESTION
Back To Top
Search