Complete the code to create an empty array in JavaScript.
const myArray = [1];In JavaScript, an empty array is created using square brackets [].
Complete the code to add a new node at the start of a linked list.
function addAtStart(head, value) {
const newNode = { data: value, next: [1] };
return newNode;
}To add a node at the start, the new node's next should point to the current head.
Fix the error in the code that removes the last element from an array.
function removeLast(arr) {
arr.[1]();
return arr;
}The pop() method removes the last element from an array.
Fill both blanks to create a linked list node and link it to the next node.
const nextNode = { data: 10, [1]: null };
const node = { data: 5, [2]: nextNode };Linked list nodes use the 'next' property to point to the next node.
Fill all three blanks to create an array of node data values from a linked list.
function listToArray(head) {
const result = [];
let current = head;
while (current [1] null) {
result.[2](current.[3]);
current = current.next;
}
return result;
}The loop continues while current is not null, pushing current.data into the array.
