JavaScript arrays are dynamic, high-level list-like data structures designed to store ordered collections of data types under a single variable. They come equipped with a rich suite of prototype methods categorized into mutating operations (such as push, pop, splice, and sort) and non-mutating operations (such as slice, concat, map, and filter). Modern ECMAScript enhancements have expanded this toolkit with non-mutating copy alternatives like toSorted(), alongside declarative iteration techniques (reduce, every, some, flatMap). Understanding how reference mutability, execution callback parameters, and index boundaries behave is essential for writing robust code and succeeding in technical interviews.
JavaScript Arrays & Array Methods MCQs
1 min read
Correct Answer: a) push()
Explanation:
The push() method appends elements to the end of an array and mutates the original array, returning the new length.
Correct Answer: c) A new array populated with the results of calling a provided function on every element
Explanation:
map() creates a brand-new array containing the results of applying the callback function to each element of the calling array.
Correct Answer: b) shift()
Explanation:
The shift() method removes the first index element, shifts subsequent indices down by one, and returns the removed value.
Correct Answer: a) filter() returns a new array of all matching elements, whereas find() returns only the first single matching element
Explanation:
filter() iterates through the entire array collecting all elements that satisfy the condition, while find() stops immediately upon finding the first match.
Correct Answer: c) 16
Explanation:
The initial value of accumulator is set to 10. Adding 1, 2, and 3 to 10 gives 16.
Correct Answer: b) flat()
Explanation:
The flat() method creates a new array with sub-array elements concatenated recursively up to the specified depth.
Correct Answer: b) Undefined
Explanation:
forEach() is designed strictly for side effects and always returns undefined, unlike map() or filter().
Correct Answer: b) slice() returns a shallow copy of a portion without mutating, whereas splice() mutates the array by removing or replacing elements in place
Explanation:
slice() is non-mutating and extracts a subset, while splice() modifies the source array directly.
Correct Answer: b) every()
Explanation:
The every() method returns true only if all elements pass the test; otherwise, it returns false.
Correct Answer: c) Array.prototype.includes()
Explanation:
includes() determines whether an array includes a certain value, returning true or false accordingly (and correctly handles NaN).
Correct Answer: a) Removes the last element from an array and returns it
Explanation:
pop() mutates the array by removing its final element and returning that element.
Correct Answer: d) unshift()
Explanation:
unshift() inserts elements at the start of an array, shifting existing elements to higher indices, and returns the new length.
Correct Answer: a) true
Explanation:
some() tests whether at least one element passes the callback test, returning true immediately upon success.
Correct Answer: c) Returns -1
Explanation:
findIndex() returns the index of the first element that satisfies the testing function, or -1 if no elements pass.
Correct Answer: b) Alphabetical order by converting elements to strings
Explanation:
Without a compare function, sort() converts elements to strings and compares their UTF-16 code unit values, which can lead to unexpected numerical sorts (e.g., '10' comes before '2').
Correct Answer: b) join()
Explanation:
The join() method creates and returns a new string by concatenating all elements in an array, separated by commas or a specified separator string.
Correct Answer: b) true
Explanation:
Array.isArray() reliably determines whether the passed value is an array, returning true for arrays and false otherwise.
Correct Answer: d) All of the above
Explanation:
Spread syntax, slice(), and Array.from() are all standard, efficient ways to create shallow copies of arrays.
Correct Answer: a) To fill all elements of an array from a start index to an end index with a static value
Explanation:
fill() mutates the array by replacing elements with a static value between specified start and end positions.
Correct Answer: b) Reverses an array *in place* and returns the mutated array
Explanation:
reverse() mutates the calling array directly by reversing the order of its elements in place.
Correct Answer: c) -1
Explanation:
indexOf() returns the first index at which a given element can be found, or -1 if it is not present.
Correct Answer: b) concat()
Explanation:
concat() is a non-mutating method used to merge arrays, returning a new combined array.
Correct Answer: a) First maps each element using a mapping function, then flattens the result into a new array of depth 1
Explanation:
flatMap() is identical to a map() followed by a flat() of depth 1, but is more efficient when combined.
Correct Answer: a) It supports negative integers to count backward from the last element
Explanation:
arr.at(-1) returns the last element of the array, whereas arr[-1] with bracket notation evaluates to undefined.
Correct Answer: b) toSorted(), toReversed(), toSpliced(), with()
Explanation:
ES2023 added copy-by-default (immutable) counterparts to traditional mutating methods: toSorted(), toReversed(), toSpliced(), and with().
Correct Answer: b) A new array with the element at the specified index replaced by the given value
Explanation:
with() is a safe, immutable way to update a single index in an array without mutating the original structure.
Correct Answer: b) An array that has empty slots (holes) where indices have no assigned elements
Explanation:
Sparse arrays contain empty slots created via omissions or explicit array constructor sizing (e.g., new Array(5)), which are often skipped by methods like map() and forEach().
Correct Answer: b) All elements are removed, effectively clearing the array
Explanation:
Setting an array's length property to 0 is a classic, high-performance way to truncate and empty an array.
Correct Answer: b) The element is deleted, leaving an empty slot (hole) and keeping the array length unchanged
Explanation:
The delete operator removes a property without updating the length or shifting indices, turning the array sparse.
Correct Answer: a) Array.from() creates an array from iterable or array-like objects, whereas Array(3) creates a sparse array with 3 empty slots
Explanation:
Passing a single number to new Array(3) creates 3 empty holes, whereas Array.from({length: 3}) populates undefined or mapped values.
Correct Answer: b) [1, 2, 3]
Explanation:
Array.of() creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.
Correct Answer: a) Copies a sequence of array elements to another position within the same array in place
Explanation:
copyWithin() shallow copies part of an array to another location in the same array without modifying its length, returning it mutated.
Correct Answer: b) An iterator yielding key/value pairs [index, element] for each index
Explanation:
arr.entries() returns a new Array Iterator object that contains the key/value pairs for each index in the array.
Correct Answer: a) An iterator yielding the keys (indices) of the array
Explanation:
arr.keys() returns a new Array Iterator object that contains the keys (indices) for each index in the array.
Correct Answer: a) An iterator yielding the values for each index in the array
Explanation:
arr.values() returns a new Array Iterator object that iterates through the values of each index.
Correct Answer: c) By comparing stringified representations or writing a custom deep equality check
Explanation:
Arrays are reference types in JavaScript, so `===` checks reference equality, not structural equality.
Correct Answer: b) "1,23,4"
Explanation:
The `+` operator triggers type coercion, converting both arrays to strings via toString() and concatenating them into "1,23,4".
Correct Answer: b) ["h", "e", "l", "l", "o"]
Explanation:
Strings are iterables in JavaScript, so spreading a string unpacks each character into an array.
Correct Answer: a) Extracting values from arrays into distinct variables using syntax like `const [a, b] = arr;`
Explanation:
Array destructuring is a convenient ES6 syntax expression to unpack values from arrays into separate variables.
Correct Answer: a) Using commas without variable names, e.g., `const [a, , c] = arr;`
Explanation:
Empty slots in array destructuring assignment patterns (using extra commas) allow skipping elements.
Correct Answer: a) Collects all remaining elements of the array into a new array
Explanation:
The rest element collects any remaining unpacked elements into a new array container.
Correct Answer: b) O(1) amortized
Explanation:
Array push operations run in constant amortized time because underlying dynamic allocations occur infrequently.
Correct Answer: b) O(n)
Explanation:
shift() requires re-indexing every single remaining element in the array down by one position, resulting in O(n) linear time.
Correct Answer: b) Array-like views onto an underlying binary data buffer (e.g., Float32Array, Uint8Array)
Explanation:
TypedArrays provide mechanism for reading and writing raw binary data streams in memory.
Correct Answer: b) [1, NaN, NaN]
Explanation:
map passes (element, index, array) to parseInt. parseInt(1, 0) is 1, parseInt(2, 1) is NaN, and parseInt(3, 2) evaluates to NaN because 3 is invalid in base 2.
Correct Answer: b) includes()
Explanation:
includes() is specifically designed to return a boolean indicating whether a value exists in the array.
Correct Answer: b) arr.length = 0
Explanation:
Setting length to 0 clears the array contents in place, preserving any other variable references pointing to that exact array object.
Correct Answer: a) Returns the value of the last element in the array that satisfies the testing function
Explanation:
findLast() iterates backwards from the end of the array to find and return the last matching element.
Correct Answer: a) The index of the last element that passes the test, or -1 if none match
Explanation:
findLastIndex() searches backward and returns the index of the last matching element.
Correct Answer: b) Yes, JS arrays are heterogeneous and can store any mix of data types
Explanation:
Unlike typed arrays or arrays in strongly-typed languages, JavaScript arrays can hold elements of any data type simultaneously.
Correct Answer: c) Whatever type the accumulator evaluates to after processing
Explanation:
reduce() can return a number, string, object, boolean, or array depending on how the accumulator is initialized and updated.
Correct Answer: c) Throws a TypeError
Explanation:
Calling reduce() on an empty array with no initial value provides no starting element, causing a TypeError.
Correct Answer: c) Using JSON.parse(JSON.stringify(arr)) or a recursive deep-clone utility
Explanation:
Spread, slice, and Array.from() only create shallow copies; nested arrays/objects must be deep cloned separately.
Correct Answer: b) Returns a shallow copy of the entire array
Explanation:
Calling slice() with no parameters extracts from index 0 to the end, producing a complete shallow clone.
Correct Answer: a) The number of elements to remove from the array starting at the start index
Explanation:
deleteCount specifies how many elements should be removed from the start index during a splice operation.
Correct Answer: b) [1, 10, 2, 3]
Explanation:
Default sorting converts numbers to strings, comparing code units ('10' comes before '2').
Correct Answer: b) arr.sort((a, b) => a - b)
Explanation:
A comparator function returning a negative, zero, or positive value based on (a - b) ensures proper numerical ascending order.
Correct Answer: b) [0, 0, 0]
Explanation:
Array(3) creates 3 empty slots, and .fill(0) replaces them with the number 0, yielding [0, 0, 0].
Correct Answer: b) 3
Explanation:
The push() method returns the new length of the array, which is 3.
Correct Answer: b) splice()
Explanation:
splice() is versatile, allowing simultaneous removal and insertion of elements at any index.
Correct Answer: b) "1,apple,true"
Explanation:
toString() returns a string representing the specified array and its elements separated by commas.
Correct Answer: b) No, it throws a SyntaxError
Explanation:
forEach() takes a callback function, so break and continue cannot be used inside it directly (use for...of or standard for loops instead).
Correct Answer: c) for...of loop
Explanation:
The for...of loop iterates over iterable array values and fully supports control flow statements like break and continue.
Correct Answer: b) true
Explanation:
The second parameter (1) specifies the starting index for the search. Searching for 2 starting from index 1 returns true.
Correct Answer: b) 1
Explanation:
The first element greater than 10 is 12, which is located at index 1.
Correct Answer: a) To store the running total or final aggregated result returned across iterations
Explanation:
The accumulator accumulates the callback's return values across each element of the array.
Correct Answer: d) All of the above
Explanation:
Array.from(), spread syntax, and old-school slice.call() all successfully convert array-like objects into genuine arrays.
Correct Answer: b) [1, 2, 3, 4]
Explanation:
Passing a depth of 2 flattens sub-arrays nested up to two levels deep, resulting in a fully flattened [1, 2, 3, 4].
Correct Answer: b) [2, 3]
Explanation:
Negative indices in slice() specify an offset from the end of the array, extracting the last two elements.
Correct Answer: b) lastIndexOf()
Explanation:
lastIndexOf() searches the array backward, returning the index of the last matching occurrence.
Correct Answer: b) It counts backward from the end of the array to determine the starting point
Explanation:
Splice accepts negative start indexes, treating them as offset indices from the array's end.
Correct Answer: b) undefined
Explanation:
Popping an empty array does nothing and returns undefined without throwing an error.
Correct Answer: b) undefined
Explanation:
Shifting an empty array returns undefined safely.
Correct Answer: c) map()
Explanation:
map() is specifically built for transforming 1:1 elements into a new array.
Correct Answer: c) reduce()
Explanation:
reduce() accumulates array items into a single final output value.
Correct Answer: c) A sparse array with length 5 and no assigned elements
Explanation:
Passing a single numeric argument to the Array constructor creates an empty sparse array with the specified length.
Correct Answer: b) Object.prototype.toString.call(arr) === '[object Array]'
Explanation:
Object toString tagging is the classic, foolproof way to verify array types across execution contexts and frames.
Correct Answer: a) [1, 2, 3, 4, 5, 6]
Explanation:
concat() flattens arrays passed as arguments one level deep while merging values.
Correct Answer: b) Mutates the original array in place and returns it
Explanation:
reverse() is a mutating method that reverses array element order in place.
Correct Answer: b) filter()
Explanation:
filter() collects all elements returning true into a new filtered array.
Correct Answer: b) true
Explanation:
Every element in the array is strictly greater than 0, so every() returns true.
Correct Answer: b) true
Explanation:
-3 is less than 0, satisfying the condition for at least one element, so some() returns true.
Correct Answer: b) "a-b-c"
Explanation:
join('-') concatenates the array elements into a string separated by hyphens.
Correct Answer: b) 1
Explanation:
The number 2 is located at index 1 of the array.
Correct Answer: b) -1
Explanation:
indexOf() uses strict equality (===) under the hood, and NaN !== NaN, so indexOf cannot locate NaN.
Correct Answer: b) true
Explanation:
Unlike indexOf(), includes() correctly handles NaN using SameValueZero equality semantics.
Correct Answer: b) arr.splice(i, 1)
Explanation:
splice(i, 1) removes 1 element at index i and shifts subsequent elements to fill the gap.
Correct Answer: a) The original array being traversed
Explanation:
Standard array method callbacks receive (element, index, array) as arguments.
Correct Answer: a) Elements beyond the new length are deleted
Explanation:
Truncating an array's length property deletes all elements at indices greater than or equal to the new length.
Correct Answer: b) true
Explanation:
Array.isArray() correctly identifies an array literal as an array.
Correct Answer: b) arr.toSorted()
Explanation:
toSorted() is the modern, immutable counterpart to sort().
Correct Answer: b) arr.toReversed()
Explanation:
toReversed() returns a new array with elements in reverse order without modifying the source array.
Correct Answer: b) They prevent accidental state mutation bugs in functional programming and state management libraries
Explanation:
Returning new copies avoids side effects and unintended mutations, making state changes predictable.
Correct Answer: a) [2, 3, 3]
Explanation:
copyWithin copies elements from index 1 onward to index 0, mutating the array in place to [2, 3, 3].
Related Posts
New
New
New

JavaScript DOM Manipulation MCQs
The Document Object Model (DOM) is a cross-platform programming interface that treats HTML and XML documents as a hierarchical tree…
August 29, 2026By MCQs Generator

Python OOP MCQs
Object-Oriented Programming (OOP) in Python is a programming paradigm that uses classes and objects to model real world entities, promoting…
August 27, 2026By MCQs Generator

Python Functions MCQs
Functions in Python are reusable blocks of code designed to perform a specific task, promoting code modularity, readability, and DRY…
August 27, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator