DOM Manipulation in JavaScript
15 questions · 12 min · Medium
Test your JavaScript knowledge with 20 questions covering arrays, array creation, indexing, adding and removing elements, and commonly used array methods such as map(), filter(), reduce(), find(), some(), every(), and sort().
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. let numbers = [10, 20, 30];
JavaScript arrays can be created using square brackets with comma-separated elements.
A. 0
JavaScript arrays use zero-based indexing, so the first element has index 0.
C. 30
The third element is stored at index 2 because JavaScript arrays start indexing from 0.
C. length
The length property returns the number of elements in an array.
A. push()
The push() method adds one or more elements to the end of an array and returns the new array length.
B. pop()
The pop() method removes and returns the last element of an array.
C. unshift()
The unshift() method adds one or more elements to the beginning of an array and returns the new array length.
A. shift()
The shift() method removes and returns the first element of an array.
B. Creates a new array by transforming each element
The map() method calls a callback for each array element and returns a new array containing the callback results.
C. [2, 4, 6]
map() multiplies each element by 2 and returns the new array [2, 4, 6].
B. A new array containing elements that pass the test
filter() creates a new array containing the elements for which the callback returns a truthy value.
B. [2, 4]
The filter condition keeps numbers whose remainder when divided by 2 is zero, producing [2, 4].
A. Reduces an array to a single accumulated value
reduce() processes array elements using an accumulator and can produce a single final value such as a sum or object.
C. 10
The reduce() operation starts with 0 and adds 1, 2, 3, and 4, producing a total of 10.
B. find()
The find() method returns the first element for which the callback returns a truthy value, or undefined if no element matches.
B. some()
The some() method returns true when at least one element passes the provided test.
B. every()
The every() method returns true only when all elements pass the provided test.
A. Checks whether the array contains a specified value
The includes() method returns true if the array contains the specified value and false otherwise.
B. [1, 2, 3]
For an array of these numeric values, the default sort order produces [1, 2, 3]. The default comparison is lexicographic, so a numeric comparator is needed for general numeric sorting.
A. join()
The join() method creates a string by concatenating array elements with a specified separator.