Microsoft
98-382 · Question #38
A JavaScript array is initialized as follows: var array = [20, 40, 60, 80]; You write the following code to manipulate the array: array.shift(); array.pop(); array.push(10); array.unshift(100); You…
The array is manipulated as follows: 1. Initial array: [20, 40, 60, 80] 2. array.shift(); // Removes 20. Array becomes: [40, 60, 80] 3. array.pop(); // Removes 80. Array becomes: [40, 60] 4. array.push(10); // Adds 10 to the end. Array becomes: [40, 60, 10] 5…
Performing Operations
Question
A JavaScript array is initialized as follows:
var array = [20, 40, 60, 80];
You write the following code to manipulate the array:
array.shift();
array.pop();
array.push(10);
array.unshift(100);
You need to determine the contents of the array. Which four elements does the array contain in sequence? To answer, move the appropriate elements from the list of elements to the answer area and arrange them in the correct order.Explanation
The array is manipulated as follows:
- Initial array: [20, 40, 60, 80]
- array.shift(); // Removes 20. Array becomes: [40, 60, 80]
- array.pop(); // Removes 80. Array becomes: [40, 60]
- array.push(10); // Adds 10 to the end. Array becomes: [40, 60, 10]
- array.unshift(100); // Adds 100 to the beginning. Array becomes: [100, 40, 60, 10]
The final contents of the array are [100, 40, 60, 10]. The elements in the answer area should be arranged in this order: 100 40 60 10
Topics
#array methods#shift#pop#push/unshift
Community Discussion
No community discussion yet for this question.